tenhobi/effective_dart

Reflect rules's "severity" using analyser

tenhobi opened this issue · 4 comments

From the Effective Dart, you have these severity types:

  • DO guidelines describe practices that should always be followed. There will almost never be a valid reason to stray from them.
  • DON’T guidelines are the converse: things that are almost never a good idea. Hopefully, we don’t have as many of these as other languages do because we have less historical baggage.
  • PREFER guidelines are practices that you should follow. However, there may be circumstances where it makes sense to do otherwise. Just make sure you understand the full implications of ignoring the guideline when you do.
  • AVOID guidelines are the dual to “prefer”: stuff you shouldn’t do but where there may be good reasons to on rare occasions.
  • CONSIDER guidelines are practices that you might or might not want to follow, depending on circumstances, precedents, and your own preference.

And as I understand, you can use four types of severity for analyzer:

  • error
  • warning
  • info
  • ignore

And more info about how it can be done here: https://dart.dev/guides/language/analysis-options#the-analysis-options-file


I would like to (and this is not opinionated, it would be nice to have in general to determine these types from the guide in the editor) reflect the type of usage from guidelines in Effective Dart, so do and don't rules are treated as they have to be done this way and prefer and avoid as only optional? With that, without enabling thins like --fatal-infos and --fatal-warnings, it would be good if analyzer would fail for dos and don'ts and don't fail for prefers and avoids.

  1. Does this have a sense, is it worth it?

For example, in pedantic package, there is written "By default we disallow checking in code with any errors, warnings, or hints." and that might work if all the lints are given the same severity, but Effective Dart doesn't have this benefit. 🤷‍♂️

  1. Can I use error for dos and don'ts, or it's too hard? Should I use warning for that?
  2. If error will be used for dos and don'ts, then warning for prefers and avoids and info for considers?
  3. if considers would have info, and therefore be shown as a "something" from Dart Analyser, wouldn't that force people to use it, whereas this section isn't always what you want to do? So maybe omit considers?

I would like some comments, mostly to be as aligned as possible with the guide intention.
Maybe cc @pq @kwalrath ...

pq commented

Also cc @munificent

+1

@bwilkerson should be at the party too.

🎈

Also, it seems that flutter analyze fails when there are infos or warnings. Is there any reason why? dartanalyze doesn't do that.

In #25 I have set up dos and don'ts as error, avoids and prefers as warning and considers as info. But to be able to show the considers to the users, I would have to enable those lints.

Also, Flutter's analyzer doesn't allow warnings and lints in the code, so that is kinda weird in comparison with Dart Analyzer.

For now, I keep considers commented out.

EDIT: Btw. as a nit, I could also enable considers and mark them as ignore.