drift icon indicating copy to clipboard operation
drift copied to clipboard

Warn about missing imports needed for generated code

Open simolus3 opened this issue 5 years ago • 2 comments

One suggestion, add some field(s) to @UseMoor where you need to list the used converters and return types. This forces the imports and maybe even allows to validate some stuff during generation.

Originally posted by @kuhnroyal in https://github.com/simolus3/moor/issues/103#issuecomment-580454160

simolus3 avatar Jan 30 '20 22:01 simolus3

Thanks for trying out type converters in moor files, @kuhnroyal!

I'm don't think forcing users to list type converters in @UseMoor is a convenient api. It's safe, sure, but it essentially forces you to copy-paste code between moor files and the annotation (and keep that in sync). Or am I missing something?

We can probably use some analyzer api to verify that all types we're using in generated code are available by imports. This would also allow us to provide warnings at build time.

simolus3 avatar Jan 30 '20 22:01 simolus3

I was thinking along the lines of

@UseMoor(
  useCustomTypes: <Type>[
    FooConverter,
    Foo,
    OffsetDate,
  ],
)

This should ofc be optional but it ensures (if used) that imports don't get lost when running automated tools (organize imports etc.) when the database.g.dart file is not generated.

kuhnroyal avatar Jan 31 '20 17:01 kuhnroyal