Skip to content

Conversation

@PiotrRogulski
Copy link
Member

@PiotrRogulski PiotrRogulski commented Nov 25, 2025

In separate PRs:

  • re-write tests
  • move implementation to src

What's not yet available:

  • use_design_system_item: separate lint rules per config entry
  • prefer_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 🙈)

@github-actions github-actions bot added the p: leancode_lint Related to the leancode_lint package label Nov 25, 2025
@PiotrRogulski
Copy link
Member Author

Actually, I might need to include the tests in this PR, since the check is complaining

@shilangyu
Copy link
Contributor

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)?

@PiotrRogulski
Copy link
Member Author

What is your opinion on how the tests look like now?

Not particularly fond of them, honestly 😅

they seem not maintainable and not made for humans to edit

That's not a huge issue; the testing tooling suggests appropriate locations:

Found but did not expect:
  use_design_system_item.use_design_system_item [57, 8, Scaffold is forbidden within this design system., "Use the alternative defined in the design system: LftScaffold."]
  use_design_system_item.use_design_system_item [106, 4, Text is forbidden within this design system., "Use the alternative defined in the design system: LftText."]

To accept the current state, expect:
  lint(57, 8),
  lint(106, 4),

Either way, I guess this is not mergable until we figure out how to support configs (which are crucial)

I mean, the config, even if not done "officially", already works

@shilangyu
Copy link
Contributor

That's not a huge issue; the testing tooling suggests appropriate locations:

Found but did not expect:
  use_design_system_item.use_design_system_item [57, 8, Scaffold is forbidden within this design system., "Use the alternative defined in the design system: LftScaffold."]
  use_design_system_item.use_design_system_item [106, 4, Text is forbidden within this design system., "Use the alternative defined in the design system: LftText."]

To accept the current state, expect:
  lint(57, 8),
  lint(106, 4),

I don't see this being useful. 57, 106 means nothing to me, I don't know which range this is indicating

@PiotrRogulski
Copy link
Member Author

That's not a huge issue; the testing tooling suggests appropriate locations:

Found but did not expect:
  use_design_system_item.use_design_system_item [57, 8, Scaffold is forbidden within this design system., "Use the alternative defined in the design system: LftScaffold."]
  use_design_system_item.use_design_system_item [106, 4, Text is forbidden within this design system., "Use the alternative defined in the design system: LftText."]

To accept the current state, expect:
  lint(57, 8),
  lint(106, 4),

I don't see this being useful. 57, 106 means nothing to me, I don't know which range this is indicating

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 🙈

@PiotrRogulski
Copy link
Member Author

@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)

@shilangyu
Copy link
Contributor

Nice! Thanks. I have started reviewing this PR btw. Just not done yet

Copy link
Contributor

@shilangyu shilangyu left a 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.

class LeancodeLintConfig {
LeancodeLintConfig._(this.configMap);

factory LeancodeLintConfig.fromRuleContext(RuleContext context) {
Copy link
Contributor

@shilangyu shilangyu Dec 7, 2025

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(
Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something weird is going on when combining yaml maps :/

Before merging – everything looks ok:

Screenshot 2025-12-08 at 10 14 46 Screenshot 2025-12-08 at 10 15 04

After merging – values are null 😔

Screenshot 2025-12-08 at 10 15 40

Copy link
Contributor

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

Copy link
Contributor

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: leancode_lint Related to the leancode_lint package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants