simolus3 / drift

Drift is an easy to use, reactive, typesafe persistence library for Dart & Flutter.
https://drift.simonbinder.eu/
MIT License
2.66k stars 372 forks source link

Linter for drift #3281

Open dickermoshe opened 1 month ago

dickermoshe commented 1 month ago

Dunno what happened to the old PR. I think the VScode Github Plugin must've closed it. Anyway, here's it as a new PR

dickermoshe commented 1 month ago

@simolus3

See how I setup the tests. Lmk if you have a better way of setting them up.

Also, Some of the async code is copied from the dart sdk, I don't know how this affects licensing.

dickermoshe commented 1 month ago

Right now warnings in manager generation are not reported in the resolver, so the linter can't use them

The warning I'm focusing on are duplicate reverse names e.g.

class User extends Table {
  late final group = integer().references(Group, #id)
  late final supergroup = integer().references(Group, #id)
}
class Group extends Table {
//   `userRefs` has 2 relations!!!
}

How would I go about this?

dickermoshe commented 1 month ago

I add a warning level to DriftAnalysisError to show orange squiggles instead of red for less severe errors

simolus3 commented 1 month ago

Right now warnings in manager generation are not reported in the resolver, so the linter can't use them

Ideally, these warnings should be discovered in the analysis step instead of during code generation. I know that some of them are easier to report during codegen, is it a lot of work to port them over to something that could run in FileAnalyzer? The parts under if (element is BaseDriftAccessor) should have the same information available to them as the generator, especially in the end when all transitive tables have been added). I can also get started on this to set up the basic infrastructure for those warnings if that works for you.

dickermoshe commented 1 month ago

Yeah, could you please do that? I tried myself, but after an hour I gave up.

dickermoshe commented 3 weeks ago

@simolus3 Any update on this. Just need you to write some scaffolding where to do these analysis.

dickermoshe commented 3 weeks ago

In FileAnalyzer I don't have access to the base element to report the error