leancodepl / flutter_corelibrary

Our core packages used for building the best Flutter apps.
https://pub.dev/publishers/leancode.co
56 stars 7 forks source link

Create tool which compares rulesets of different `analysis_options.yaml` #102

Open shilangyu opened 1 year ago

shilangyu commented 1 year ago

Idea: I'd like to have an easy way to diff the rules enabled by flutter_lints and by leancode_lint.

_Originally posted by @bartekpacia in https://github.com/leancodepl/flutter_corelibrary/pull/101#pullrequestreview-1427304922_

bartekpacia commented 1 year ago

Sounds like a fun task for somebody with some free time :)

I'll write my idea for it:

This tool would accept a lints yaml file, e.g. the one from flutter_lints and print all the rules it contains. If the lints yaml file includes other lints yaml files, rules from them must be recursively added to the result.

So in flutter_lints case:

flutter.yaml -> https://github.com/flutter/packages/blob/main/packages/flutter_lints/lib/flutter.yaml
└── recommended.yaml -> https://github.com/dart-lang/lints/blob/main/lib/recommended.yaml
    └── core.yaml -> https://github.com/dart-lang/lints/blob/main/lib/core.yaml

Maybe there's some existing package that already does this?

I also think it must for sure already exist somewhere in the analyzer internals.

shilangyu commented 1 year ago

I already started researching this yesterday. Here is the place that implements this logic: https://github.com/dart-lang/sdk/blob/84f528d26dae3c75cad7c850321cbf1a15f96361/pkg/analyzer/lib/src/analysis_options/analysis_options_provider.dart#L63

Requires extra research how to actually use this outside of analyzer

bartekpacia commented 1 year ago

Can a package depend on analyzer just like on any other package?

Depending on stuff from packages's src is bad but there's probably no other option in this case.

shilangyu commented 1 year ago

Can a package depend on analyzer just like on any other package?

Yes

Depending on stuff from packages's src is bad but there's probably no other option in this case.

Not sure why it isnt re-exported from lib. It seems the dart compiler packages import from src/ all the time for some reason. Looks like even outside packages import src/, like build_runner: https://github.com/dart-lang/build/blob/96e0ba6044a0620b31d99468e19b063367f7f410/build_resolvers/lib/src/resolver.dart#L16