Rule Catalog

Falcon includes 58+ lint rules organized into 6 categories. These rules help you catch bugs, enforce best practices, and improve code quality across your Flutter and Dart projects.

Common Rules

31 rules covering general Dart best practices, type safety, and code style.

Rule Severity Description
avoid-dynamicErrorDiscourages use of the dynamic type; prefer explicit types for better type safety.
avoid-empty-catchErrorFlags empty catch blocks that silently swallow exceptions; require proper error handling.
avoid-global-stateErrorWarns against mutable global variables that make code harder to test and reason about.
avoid-hardcoded-credentialsErrorDetects hardcoded passwords, API keys, or secrets in source code.
avoid-throw-in-catchErrorFlags re-throwing errors in catch blocks without proper wrapping or context.
avoid-unawaited-futuresErrorDetects Future calls that are not awaited, which can cause unhandled errors.
avoid-late-keywordWarningSuggests alternatives to late when initialization can be guaranteed.
avoid-long-functionsWarningDiscourages functions that exceed a configurable length threshold.
avoid-long-parameter-listWarningFlags functions with too many parameters; suggests using objects or records.
avoid-nested-conditionalsWarningEncourages early returns to reduce nesting depth.
avoid-non-ascii-symbolsWarningDiscourages non-ASCII characters in identifiers for portability.
avoid-print-in-productionWarningFlags print statements that should be removed or replaced with logging.
avoid-unnecessary-type-assertionsWarningDetects redundant ! or type assertions when type is already known.
avoid-unnecessary-type-castsWarningFlags unnecessary as casts that add no value.
avoid-unused-parametersWarningDetects function parameters that are never used.
avoid-cascade-after-if-nullWarningWarns about cascades after ?? which may not behave as expected.
avoid-collection-methods-unrelated-typesWarningFlags collection methods used with incompatible element types.
avoid-double-negationWarningDiscourages !! or redundant negation patterns.
avoid-duplicate-exportsWarningDetects duplicate export directives in library files.
avoid-missing-enum-constant-in-mapWarningEnsures all enum values are handled in switch/map expressions.
avoid-top-level-members-in-testsWarningDiscourages top-level variables in test files that can cause test pollution.
prefer-correct-identifier-lengthWarningEnforces reasonable identifier length for readability.
prefer-match-file-nameWarningEnsures library/part names match the file name.
prefer-named-boolean-parametersWarningSuggests named parameters for boolean arguments to improve clarity.
prefer-specific-catch-typeWarningEncourages catching specific exception types instead of Object.
no-magic-numbersWarningFlags unexplained numeric literals; suggests named constants.
binary-expression-operand-orderInfoEnforces consistent operand order in binary expressions.
double-literal-formatInfoEnforces consistent formatting of double literals.
newline-before-returnInfoRequires a blank line before return statements.
prefer-first-lastInfoSuggests first/last over [0]/[length-1] for iterables.
prefer-trailing-commaInfoEncourages trailing commas in multi-line collections for cleaner diffs.

Flutter Rules

11 rules specific to Flutter widget lifecycle, performance, and accessibility.

Rule Severity Description
ensure-dispose-lifecycleErrorEnsures controllers and subscriptions are disposed in dispose().
ensure-stream-subscription-cancelErrorRequires StreamSubscription to be cancelled to prevent memory leaks.
avoid-unnecessary-setstateErrorFlags unnecessary setState calls that don't change state.
avoid-returning-widgetsWarningDiscourages returning widgets from non-build methods; prefer extracting widgets.
avoid-excessive-widget-nestingWarningFlags deeply nested widget trees that hurt readability and performance.
prefer-const-constructorsWarningSuggests const constructors when widgets don't depend on runtime values.
prefer-extracting-callbacksWarningEncourages extracting inline callbacks to named methods for clarity.
ensure-semantics-labelWarningRequires semantic labels for interactive widgets for accessibility.
ensure-image-semanticsWarningEnsures images have semantic labels for screen readers.
avoid-expanded-as-spacerInfoSuggests SizedBox or Spacer instead of Expanded for spacing.
ensure-touch-target-sizeInfoEnsures touch targets meet minimum size (e.g., 48x48 logical pixels).

Code Examples

avoid-empty-catch

Empty catch blocks silently swallow exceptions, making debugging difficult. Always handle or rethrow errors.

Bad

try {
  await fetchData();
} catch (e) {
  // empty — error is silently ignored
}

Good

try {
  await fetchData();
} catch (e, stackTrace) {
  logError(e, stackTrace);
  rethrow;
}

ensure-dispose-lifecycle

Controllers and subscriptions must be disposed to prevent memory leaks. Override dispose() and clean up resources.

Bad

class MyWidget extends StatefulWidget {
  final TextEditingController controller =
      TextEditingController();
  // Missing dispose — controller leaks
}

Good

class MyWidget extends StatefulWidget {
  final TextEditingController controller =
      TextEditingController();

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }
}

avoid-unawaited-futures

Futures must be awaited to handle errors and ensure proper execution order. Unawaited futures can cause unhandled exceptions.

Bad

void saveData() {
  writeToFile(data);  // Future not awaited — errors lost
}

Good

Future<void> saveData() async {
  await writeToFile(data);
}

BLoC Rules

5 rules for projects using the BLoC pattern for state management.

Rule Severity Description
bloc-avoid-public-membersWarningEncourages encapsulating BLoC internals; avoid exposing implementation details.
bloc-avoid-context-readWarningDiscourages context.read in build methods; prefer BlocBuilder/BlocListener.
bloc-close-subscriptionErrorEnsures Bloc is closed when no longer needed to prevent leaks.
bloc-avoid-emit-after-closeErrorFlags emit calls after the bloc has been closed.
bloc-prefer-cubitInfoSuggests Cubit over full Bloc when events are not needed.

Provider / Riverpod Rules

5 rules for projects using Provider or Riverpod for dependency injection and state management.

Rule Severity Description
provider-disposeErrorEnsures Provider resources are properly disposed when no longer needed.
provider-avoid-context-read-in-buildWarningDiscourages context.read/watch in build; use Consumer or context extensions.
riverpod-avoid-dispose-in-buildErrorFlags ref.dispose or similar calls during build phase.
riverpod-prefer-refInfoSuggests using ref over context when both are available in providers.
riverpod-keep-aliveInfoRecommends autoDispose or keepAlive based on provider lifecycle needs.

Equatable Rules

3 rules for projects using Equatable for value equality.

Rule Severity Description
equatable-props-completeErrorEnsures all relevant properties are listed in the props getter.
equatable-avoid-mutable-propsWarningDiscourages mutable types in Equatable props; use immutable copies.
equatable-prefer-constInfoSuggests const constructors for Equatable classes when possible.

Presets

Presets bundle related rules for quick configuration. Choose a preset that matches your project's dependencies.

Preset Rule Count Description
recommended42Default preset with common and Flutter rules; suitable for most projects.
strict58All rules enabled; maximum enforcement for high-compliance projects.
minimal12Only critical error-level rules; minimal friction for new projects.
bloc47Recommended + BLoC rules; for projects using flutter_bloc.
riverpod47Recommended + Riverpod rules; for projects using flutter_riverpod.
provider46Recommended + Provider rules; for projects using provider.