Skip to content

Add the bloc_related_class_naming lint#504

Merged
PiotrRogulski merged 7 commits intomasterfrom
bloc-related-class-naming-lint
Feb 27, 2026
Merged

Add the bloc_related_class_naming lint#504
PiotrRogulski merged 7 commits intomasterfrom
bloc-related-class-naming-lint

Conversation

@PiotrRogulski
Copy link
Member

Continuation of #458

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new bloc_related_class_naming lint to enforce naming conventions for Bloc/Cubit-related types (Event/State/Presentation Event), building on the bloc-architecture lint set introduced in #458.

Changes:

  • Introduce BlocRelatedClassNaming lint that inspects Bloc/Cubit generic type arguments (and BlocPresentationMixin usage).
  • Add shared bloc inspection helpers (bloc_utils.dart) to identify bloc/cubit types and extract relevant type annotations.
  • Add test coverage and test-only mock libraries (including bloc_presentation), register the lint in the plugin, and document it in the README.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/leancode_lint/lib/src/lints/bloc_related_class_naming.dart Implements the new lint and reporting logic for related class naming.
packages/leancode_lint/lib/src/bloc_utils.dart Adds shared utilities for detecting bloc/cubit classes and extracting event/state/presentation-event types.
packages/leancode_lint/lib/plugin.dart Registers the new lint in the plugin.
packages/leancode_lint/README.md Documents the new lint and its naming rules.
packages/leancode_lint/test/test_cases/bloc_related_class_naming_test.dart Adds tests verifying diagnostics for bloc/cubit naming and external-library ignore behavior.
packages/leancode_lint/test/mock_libraries/bloc.dart Extends the bloc mock to include BlocBase and Bloc, enabling bloc tests.
packages/leancode_lint/test/mock_libraries/bloc_presentation.dart Adds a mock bloc_presentation package with BlocPresentationMixin.
packages/leancode_lint/test/mock_libraries.dart Wires the new bloc_presentation mock into the test harness.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


None.

### `bloc_related_class_naming`
Copy link
Member

Choose a reason for hiding this comment

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

update with main. it's in <details> now


> [!NOTE]
> This lint only checks classes defined in the same library (including parts) as the Bloc/Cubit.
> Presentation events are only checked if the `bloc_presentation` package is used.
Copy link
Member

Choose a reason for hiding this comment

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

Presentation events are only checked if the bloc_presentation package is used.

What does "used" mean here? If it's imported?

Copy link
Member Author

Choose a reason for hiding this comment

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

If the "presentation" is implemented with the bloc_presentation package (there might be different offerings; we don't check those)

/// should be named:
/// - state → `FooState`
/// - event → `FooEvent`
/// - presentation event → `FooPresentationEvent` (BLoC) or `FooEvent` (Cubit)
Copy link
Member

Choose a reason for hiding this comment

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

or FooEvent (Cubit)

oof I'm not too sure about that one. This might be confusing if we have events as events and PEs.

Let's make these names configurable in the rule (all of them, because why not)

Copy link
Member Author

Choose a reason for hiding this comment

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

Allowing config makes sense; what would it look like, though? 🤔 Something like this?

LeanCodeLintConfig(
  blocRelatedClassNaming: .new(
    stateSuffix: 'State',
    eventSuffix: .new(
      bloc: 'PresentationEvent',
      cubit: 'Event',
    ),
  ),
);

Copy link
Member

Choose a reason for hiding this comment

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

stateSuffix, eventSuffix, presentationEventSuffix.

I'd drop having different names for PEs in cubits and blocs


final AnalysisRule rule;
final RuleContext context;
final LeanCodeLintConfig config;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
final LeanCodeLintConfig config;
final BlocRelatedClassNamingConfig config;

SRP

@PiotrRogulski PiotrRogulski merged commit 3a26219 into master Feb 27, 2026
2 checks passed
@PiotrRogulski PiotrRogulski deleted the bloc-related-class-naming-lint branch February 27, 2026 18:06
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