Skip to main content

prefer-bloc-state-suffix

added in: 1.25.0
⚙️
Free+

Warns when a Bloc state class name does not match the configured pattern.

⚙️ Config

Set name-pattern (default is State$) to set a regular expression pattern for bloc state names.

Set ignore-subclasses (default is true) to skip the name check for state subclasses.

analysis_options.yaml
dart_code_metrics:
rules:
- prefer-bloc-state-suffix:
name-pattern: State$
ignore-subclasses: true

Example

❌ Bad:

class SomeClass {}

// LINT: The name of the bloc state class is expected to match the configured suffix: 'State$'.
class CounterBloc extends Bloc<CounterEvent, SomeClass> {
...
}

✅ Good:

class SomeState {}

class CounterBloc extends Bloc<CounterEvent, SomeState> {
...
}