Add the bloc_related_class_naming lint#504
Conversation
There was a problem hiding this comment.
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
BlocRelatedClassNaminglint that inspects Bloc/Cubit generic type arguments (andBlocPresentationMixinusage). - 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.
packages/leancode_lint/README.md
Outdated
|
|
||
| None. | ||
|
|
||
| ### `bloc_related_class_naming` |
There was a problem hiding this comment.
update with main. it's in <details> now
packages/leancode_lint/README.md
Outdated
|
|
||
| > [!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. |
There was a problem hiding this comment.
Presentation events are only checked if the
bloc_presentationpackage is used.
What does "used" mean here? If it's imported?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Allowing config makes sense; what would it look like, though? 🤔 Something like this?
LeanCodeLintConfig(
blocRelatedClassNaming: .new(
stateSuffix: 'State',
eventSuffix: .new(
bloc: 'PresentationEvent',
cubit: 'Event',
),
),
);There was a problem hiding this comment.
stateSuffix, eventSuffix, presentationEventSuffix.
I'd drop having different names for PEs in cubits and blocs
|
|
||
| final AnalysisRule rule; | ||
| final RuleContext context; | ||
| final LeanCodeLintConfig config; |
There was a problem hiding this comment.
| final LeanCodeLintConfig config; | |
| final BlocRelatedClassNamingConfig config; |
SRP
Continuation of #458