-
Notifications
You must be signed in to change notification settings - Fork 13
Migrate lints to analysis server plugin #494
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Actually, I might need to include the tests in this PR, since the check is complaining |
|
What is your opinion on how the tests look like now? To me, they seem not maintainable and not made for humans to edit. I also do not like that we are mocking libraries rather than testing on the real thing. If you think the previous testing framework was better, I can try to write something that will make it work (if I find time). We can improve on what custom lint did and expect lints in some specific range rather than in the next line. Either way, I guess this is not mergable until we figure out how to support configs (which are crucial)? There could be a gradual migration of lints that don't need custom_lint features but still stay with custom_lint for the rest. What do you think (or, what is LeanCode's roadmap for leancode_lint here)? |
Not particularly fond of them, honestly 😅
That's not a huge issue; the testing tooling suggests appropriate locations:
I mean, the config, even if not done "officially", already works |
I don't see this being useful. |
Yes, in this regard the experience is very poor. I just end up selecting text in the editor and seeing how many characters I select 🙈 |
|
@shilangyu Actually, I'll try refactoring the tests to use TestCode and range-based markup (dart-lang/sdk#61889, maybe someday it'll be oficially supported; for now it works with a src import) |
|
Nice! Thanks. I have started reviewing this PR btw. Just not done yet |
shilangyu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this huge effort! This is amazing. It is nice to finally get first party support in dart.
packages/leancode_lint/lib/assists/convert_iterable_map_to_collection_for.dart
Show resolved
Hide resolved
packages/leancode_lint/lib/assists/convert_positional_to_named_formal.dart
Show resolved
Hide resolved
packages/leancode_lint/lib/assists/convert_record_into_nominal_type.dart
Show resolved
Hide resolved
packages/leancode_lint/test/test_cases/add_cubit_suffix_for_cubits_test.dart
Show resolved
Hide resolved
| class LeancodeLintConfig { | ||
| LeancodeLintConfig._(this.configMap); | ||
|
|
||
| factory LeancodeLintConfig.fromRuleContext(RuleContext context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This unfortunately reads only analysis_options from the root of the workspace. It is an important feature (and used at LeanCode) that configs are scoped to some directory.
package:analyzer/src/analysis_options handles this. See the AnalysisOptionsProvider class. It also handles merging options from upper configs and resolves include: directives.
| .new([package.workspace.packageUriResolver]), | ||
| ); | ||
|
|
||
| final analysisOptionsFile = provider.getOptionsFile( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this method does merging of include:s. getOptions did.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
U right. getOptions doesn't seem to behave well in tests (it returns a map with all the correct keys, but with null values: {analyzer: null, linter: null, leancode_lint: null} 🤔) Will have to investigate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will have a look at it by the end of the week, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spent some time debugging this. It really seems like a bug. I tried to look at how the SDK uses this API but found nothing jarring. I hope to find more time this week (but it is very busy for me) to resolve this finally.
| import 'package:analyzer_plugin/utilities/range_factory.dart'; | ||
| import 'package:custom_lint_builder/custom_lint_builder.dart'; | ||
| import 'package:leancode_lint/helpers.dart'; | ||
| // TODO: decide what to do with this lint in light of https://github.com/dart-lang/sdk/issues/61517 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I gathered from the SDK team responses is that there is no good way to resolve this. I think we need to give up on computeConstantValue approach and just hardcode some cases. Or, I can try the proposed approach of crawling from the Align widget to the Alignment.center constant. I wonder how expensive this is.



In separate PRs:
re-write testssrcWhat's not yet available:
use_design_system_item: separate lint rules per config entryprefer_center_over_align: our current implementation requires an asynchronous resolution of another library, which isn't (yet?) possible(cc @shilangyu, I can't add you as a reviewer 🙈)