Static Analysis, Linting and Formatting

Analyzer plugins (Dart 3.9+ support for custom lint rules) and custom_lint let you write your own rules (e.g., riverpod_lint).

Ignore a lint locally: // ignore: avoid_print or // ignore_for_file: lint_name.

# analysis_options.yaml
include: package:lints/recommended.yaml      # or package:flutter_lints/flutter.yaml, very_good_analysis

analyzer:
  language:
    strict-casts: true
    strict-inference: true
    strict-raw-types: true
  errors:
    unused_import: error
    missing_return: error
  exclude:
    - "**/*.g.dart"
    - "**/*.freezed.dart"

linter:
  rules:
    - prefer_const_constructors
    - prefer_final_locals
    - avoid_print
    - unawaited_futures
    - always_declare_return_types
    - require_trailing_commas
    - use_super_parameters
dart analyze                     # errors, warnings, lints
dart analyze --fatal-infos       # fail CI on infos too
dart fix --dry-run               # preview automated fixes
dart fix --apply
dart format .                    # canonical formatting (the "tall style" formatter in Dart 3.7+)
dart format --output=none --set-exit-if-changed .   # CI check