The standard Dart and Flutter analyser configuration used at hedgehog lab. A project adopts it with one include: line, and gets the same lint rules, strict language modes and generated-code excludes as every other hedgehog lab project.
This package is a maintained fork of netsells/flutter-analysis, which was itself inspired by very_good_analysis. See Attribution.
Add the package as a git dependency, pinned to a tag, in pubspec.yaml:
dev_dependencies:
hedgehoglab_flutter_analysis:
git:
url: https://github.com/hedgehoglab-engineering/flutter-analysis.git
ref: 6.0.0Then include the versioned file in analysis_options.yaml:
include: package:hedgehoglab_flutter_analysis/analysis_options.6.0.0.yamlRun flutter pub get, then flutter analyze. Expect new findings on the first run: 6.0.0 turns on strict-casts, strict-inference and strict-raw-types.
Requires Dart 3.13 or later. The package is not published to pub.dev.
- The rule set from 5.0.0, minus rules that no longer exist or are deprecated in Dart 3, plus
flutter_style_todos. See the CHANGELOG for the exact list. strict-casts,strict-inferenceandstrict-raw-types.- Excludes for generated code (
*.g.dart,*.freezed.dart,*.gr.dart,*.mocks.dart) and the platform directories. - Severity overrides inherited from Netsells (
missing_returnandmissing_required_paramas errors,close_sinksandinvalid_annotation_targetignored). lines_longer_than_80_charsstays on. It matches the defaultdart formatpage width, and it catches what the formatter cannot wrap (long strings and comments). A project that sets a differentpage_widthshould override the rule in its ownanalysis_options.yaml.
Each release that changes rules adds a new versioned file, lib/analysis_options.X.Y.Z.yaml. Earlier files are never edited, so a project that includes analysis_options.6.0.0.yaml gets the same rules for as long as it pins that file.
- Projects pin both the git
refand the versioned file in theinclude:line. Upgrading is a deliberate change to both, reviewed like any other dependency bump. lib/analysis_options.yamlalways points at the latest version. Including it means rules can change under you on the nextpub upgrade, so avoid it in projects with a clean-analyser CI gate.- New or tightened rules (and anything that makes a clean project fail) get a new major or minor version. Removing a rule the SDK no longer supports is also a new version, because the old file stops being accurate on newer SDKs.
- Replace the dependency with the git dependency above.
- Change the include to
package:hedgehoglab_flutter_analysis/analysis_options.6.0.0.yaml. - Fix new findings from the strict language modes. If a project cannot absorb them at once, include
analysis_options.5.0.0.yamlfirst (the Netsells rules, unchanged) and move to 6.0.0 in a separate change.
- Add the dependency and replace the copied
linter:block with the include line. - Keep only project-specific
analyzer:entries (extra excludes or severity changes) andlinter.rulesoverrides. Anything that duplicates 6.0.0 can go. - Run
flutter analyzeand compare with the previous result. The usual differences are the strict modes and the generated-code excludes.
Some rules are undesirable in particular places. Suppress at the line, file or project level.
A line:
// ignore: public_member_api_docs
class A {}A file:
// ignore_for_file: public_member_api_docsA project: override the rule in the project's analysis_options.yaml after the include: line.
linter:
rules:
lines_longer_than_80_chars: falseCI formats and analyses the package and the example project with --fatal-infos, and fails on any undefined, removed or deprecated lint. Before adding a rule, check its status on dart.dev. Run the same checks locally:
dart format --output=none --set-exit-if-changed .
dart analyze --fatal-infos .
dart analyze --fatal-infos exampleCreated by Netsells and released under the MIT licence. The original copyright notice is retained in LICENSE, with hedgehog lab's alongside it.