| name | dart-run-static-analysis |
| description | Configure project linter rules, configure `analysis_options.yaml`, enforce strict static type checking, and manage fine-grained file or line-level diagnostic suppressions. |
| metadata | {"platforms":"dart","languages":"dart","category":"analysis"} |
Contents
Analysis Configuration
Enforce strict formatting, stylistic cleanliness, and code sanity by configuring analysis_options.yaml in the root of your Dart package:
Diagnostic Suppression Rules
When an analyzer warning or style lint yields a false positive or hits generated files, suppress the warning explicitly using one of these strategies:
Workflow: Running Static Analysis
Follow this checklist to perform static code auditing:
Workflow: Applying Automated Code Fixes
Follow this checklist to apply mechanical quick-fixes automatically:
Examples
Comprehensive analysis_options.yaml Template
include: package:lints/recommended.yaml
analyzer:
exclude:
- "lib/generated/**"
- "**/*.g.dart"
- "**/*.freezed.dart"
language:
strict-casts: true
strict-inference: true
strict-raw-types: true
errors:
todo: ignore
missing_required_param: error
missing_return: error
linter:
rules:
always_declare_return_types: true
avoid_empty_else: true
prefer_const_constructors: true
sort_pub_dependencies: false
formatter:
page_width: 100
trailing_commas: preserve
Inline Suppression Techniques
// 1. Suppress all instances of unused variables inside this specific file
// ignore_for_file: unused_local_variable
void calculateMetrics() {
// 2. Suppress a single line using a preceding comment ignore
// ignore: invalid_assignment
int x = 'not_an_int';
final unusedString = 'value'; // File-level ignore handles this
// 3. Suppress at the end of the line
final double pi = 3.14; // ignore: constant_identifier_names
}