Skip to content

[leancode_lint] Handle Dart 3.13 primary constructors - #564

Merged
PiotrRogulski merged 5 commits into
masterfrom
claude/dart-3-13-primary-constructors-bwgurg
Aug 15, 2026
Merged

[leancode_lint] Handle Dart 3.13 primary constructors#564
PiotrRogulski merged 5 commits into
masterfrom
claude/dart-3-13-primary-constructors-bwgurg

Conversation

@PiotrRogulski

Copy link
Copy Markdown
Member

Makes the custom lints handle Dart 3.13's primary constructors, with new test cases for every affected rule.

Lint fixes

  • missing_equatable_props: fields declared by a primary constructor's declaring parameters (class MyState(final int a) with Equatable) are now required in props, and a superclass declaring its fields in a primary constructor now triggers the super.props requirement (such fields report isOriginDeclaringFormalParameter, not isOriginDeclaration). The quick-fix handles both as well.
  • constructor_parameters_and_fields_should_have_the_same_order: header-declared fields now participate in the field order (preceding body fields) when checking the class's other constructors. This also fixes a false positive where a factory's parameters matched the true field order but the lint only saw body fields.
  • avoid_build_context_in_blocs: BuildContext parameters in a Bloc/Cubit's primary constructor header (plain and field-declaring) are now reported.
  • prefer_abstract_final_class: a private class MyConstants._() primary constructor with no parameters and no this body is now recognized as an instantiation guard (including class const), and the fix removes it from the class header.
  • convert_positional_to_named_formal assist: now preserves the parameter's own declaration instead of synthesizing required this.<name>, which corrupted a primary constructor's declaring parameters (final int x) and super.x parameters.

Notes

  • Naming lints (add_cubit_suffix_for_cubits, bloc_related_class_naming, bloc_subclasses_naming, prefix_widgets_returning_slivers) already use namePart.typeName and needed no changes; a primary-constructor regression test was added for add_cubit_suffix_for_cubits.
  • Non-declaring header parameters (int x without final/var) are correctly not treated as fields.
  • All analyzer APIs used exist at the constraint floor (analyzer 13.0.0), so no constraint bump is needed.
  • Tests were verified to fail without the lint fixes (11 failures across the four rules on the old implementations).

🤖 Generated with Claude Code

https://claude.ai/code/session_01KiMgutpA35YKFfcHdXDt6E


Generated by Claude Code

claude added 4 commits August 14, 2026 09:37
- missing_equatable_props: require fields declared by a primary
  constructor's declaring parameters in props, and account for
  superclasses declaring their fields in a primary constructor when
  deciding whether super.props is needed
- constructor_parameters_and_fields_should_have_the_same_order: treat
  primary-constructor-declared fields as preceding body fields when
  checking other constructors
- avoid_build_context_in_blocs: report BuildContext parameters declared
  in a bloc/cubit primary constructor header
- prefer_abstract_final_class: recognize a private `._()` primary
  constructor as an instantiation guard and teach the fix to remove it
  from the class header
- convert_positional_to_named_formal assist: preserve the parameter's
  own declaration instead of synthesizing a `this.`-prefixed one, which
  broke declaring and super parameters

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KiMgutpA35YKFfcHdXDt6E
…tor test

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KiMgutpA35YKFfcHdXDt6E
@github-actions github-actions Bot added the p: leancode_lint Related to the leancode_lint package label Aug 14, 2026
@PiotrRogulski
PiotrRogulski marked this pull request as ready for review August 14, 2026 09:59
@PiotrRogulski
PiotrRogulski requested a review from mchudy as a code owner August 14, 2026 09:59
@PiotrRogulski
PiotrRogulski requested a review from cupofme August 15, 2026 08:12
@PiotrRogulski
PiotrRogulski merged commit 0b1e801 into master Aug 15, 2026
4 checks passed
@PiotrRogulski
PiotrRogulski deleted the claude/dart-3-13-primary-constructors-bwgurg branch August 15, 2026 10:55
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