prefer-sealed-bloc-events

Path
lint/correctness/prefer-sealed-bloc-events
Default
On (recommended)
Origin
Falcon
Domain
bloc
Rule
403 of 512
recommendedbloc

Flags Bloc event classes without a sealed or final modifier.

Closed hierarchies make exhaustive handling reliable. Identifies roots from the generic arguments of package-confirmed Bloc 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

example.dartdart
import 'package:bloc/bloc.dart';
import 'package:flutter_bloc/flutter_bloc.dart' as fb;
import 'package:meta/meta.dart';

abstract class Action {}
class First extends Action {}
class Second extends Action {}
class Deep extends First {}
class Other {}
class Example extends Bloc<Action, int> { Example() : super(0); }
class Another extends fb.Bloc<Other, int> { Another() : super(0); }

class UnrelatedEvent {}
class UnrelatedState {}
Declare this Bloc event `sealed` or `final`.
4
5abstract class Action {}
Declare this Bloc event `sealed` or `final`.
5abstract class Action {}
6class First extends Action {}
Declare this Bloc event `sealed` or `final`.
6class First extends Action {}
7class Second extends Action {}
Declare this Bloc event `sealed` or `final`.
7class Second extends Action {}
8class Deep extends First {}
Declare this Bloc event `sealed` or `final`.
8class Deep extends First {}
9class Other {}

Valid

example.dartdart
import 'package:bloc/bloc.dart';
import 'package:meta/meta.dart';

sealed class Action {}
final class First extends Action {}
final class Second extends Action {}
class Example extends Bloc<Action, int> { Example() : super(0); }
final class Other {}
class Another extends Bloc<Other, int> { Another() : super(0); }

class UnrelatedEvent {}
class UnrelatedState {}
class NoSuffix {}

Configure prefer-sealed-bloc-events

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "correctness": {
        "prefer-sealed-bloc-events": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/correctness/prefer-sealed-bloc-events: <reason>
  • prefer-sealed-bloc-staterecommendedbloc

    Flags Bloc state classes without a sealed or final modifier.

  • prefer-void-to-nullprefer_void_to_nullrecommended

    Flags uses of the Null type where void is meant.

  • proper-controller-disposeproper_controller_disposerecommendedflutter

    Requires Flutter controllers owned by a State field to be disposed.

  • proper-expanded-and-flexibleproper_expanded_and_flexiblerecommendedflutter

    Require Expanded and Flexible to sit directly inside a flex widget.

  • proper-from-environmentproper_from_environmentrecommended

    Require fromEnvironment to be evaluated in a const context.

  • proper-super-init-stateproper_super_init_staterecommendedflutter

    Require super.initState() to be the first statement of a resolved Flutter State subclass's initState override.

  • require-super-disposerecommendedflutter

    Require super.dispose() in Flutter State dispose overrides.

  • sort-pub-dependenciessort_pub_dependenciescross-file

    Require pubspec.yaml dependency sections to be sorted alphabetically.