prefer-sealed-bloc-state
- Group
- Correctness
- Path
lint/correctness/prefer-sealed-bloc-state- Default
- On (recommended)
- Origin
- Falcon
- Domain
- bloc
- Rule
- 404 of 512
Flags Bloc state classes without a sealed or final modifier.
Closed hierarchies make exhaustive handling reliable. Identifies roots from the generic arguments of package-confirmed Bloc or Cubit superclasses, then checks those roots and their resolved subclasses. Unrelated name suffixes and unresolved model types are ignored. Both sealed and final satisfy the rule. Roots and declarations must be in the current file; separate part files are not joined.
Invalid
import 'package:bloc/bloc.dart';
import 'package:flutter_bloc/flutter_bloc.dart' as fb;
import 'package:meta/meta.dart';
abstract class Snapshot {}
class First extends Snapshot {}
class Second extends Snapshot {}
class Deep extends First {}
class Other {}
class Example extends Bloc<int, Snapshot> { Example() : super(First()); }
class Another extends fb.Cubit<Other> { Another() : super(Other()); }
class UnrelatedEvent {}
class UnrelatedState {} abstract class Snapshot {}abstract class Snapshot {}class First extends Snapshot {}class First extends Snapshot {}class Second extends Snapshot {}class Second extends Snapshot {}class Deep extends First {}class Deep extends First {}class Other {}Valid
import 'package:bloc/bloc.dart';
import 'package:meta/meta.dart';
sealed class Snapshot {}
final class First extends Snapshot {}
final class Second extends Snapshot {}
class Example extends Bloc<int, Snapshot> { Example() : super(First()); }
final class Other {}
class Another extends Cubit<Other> { Another() : super(Other()); }
class UnrelatedEvent {}
class UnrelatedState {}
class NoSuffix {}Configure prefer-sealed-bloc-state
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"prefer-sealed-bloc-state": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/prefer-sealed-bloc-state: <reason>More correctness rules
- prefer-void-to-null
prefer_void_to_nullrecommendedFlags uses of the
Nulltype wherevoidis meant. - proper-controller-dispose
proper_controller_disposerecommendedflutterRequires Flutter controllers owned by a
Statefield to be disposed. - proper-expanded-and-flexible
proper_expanded_and_flexiblerecommendedflutterRequire
ExpandedandFlexibleto sit directly inside a flex widget. - proper-from-environment
proper_from_environmentrecommendedRequire
fromEnvironmentto be evaluated in a const context. - proper-super-init-state
proper_super_init_staterecommendedflutterRequire
super.initState()to be the first statement of a resolved FlutterStatesubclass'sinitStateoverride. - require-super-disposerecommendedflutter
Require
super.dispose()in Flutter State dispose overrides. - sort-pub-dependencies
sort_pub_dependenciescross-fileRequire
pubspec.yamldependency sections to be sorted alphabetically. - test-types-in-equals
test_types_in_equalsrecommendedFlags casting the parameter of
operator ==instead of testing its type.