dart-run-static-analysis
Analyzing and Fixing Dart Code
Contents
- Analysis Configuration
- Diagnostic Suppression
- Workflow: Executing Static Analysis
- Workflow: Applying Automated Fixes
- Examples
Analysis Configuration
Configure the Dart analyzer using the analysis_options.yaml file located at the package root.
- Base Configuration: Always include a standard rule set (e.g.,
package:lints/recommended.yamlorpackage:flutter_lints/flutter.yaml) using theinclude:directive. - Strict Type Checks: Enable strict type checks under the
analyzer: language:node to prevent implicit downcasts and dynamic inferences. Setstrict-casts: true,strict-inference: true, andstrict-raw-types: true. - Linter Rules: Explicitly enable or disable specific rules under the
linter: rules:node. Use a key-value map (rule_name: true/false) when overriding included rules, or a list (- rule_name) when defining a fresh set. Do not mix list and map syntax in the samerulesblock. - Formatter Configuration: Configure
dart formatbehavior under theformatter:node. Setpage_width(default 80) andtrailing_commas(automateorpreserve). - Analyzer Plugins: Enable custom diagnostics by adding plugins under the
analyzer: plugins:node. Ensure the plugin package is added as adev_dependencyinpubspec.yaml.
Diagnostic Suppression
More from dart-lang/skills
dart-add-unit-test
Write and organize unit tests for functions, methods, and classes using `package:test`. Use when creating new logic or fixing bugs to ensure code remains correct and regression-free.
2.1Kdart-fix-runtime-errors
Uses get_runtime_errors and lsp to fetch an active stack trace, locate the failing line, apply a fix, and verify resolution via hot_reload.
2.1Kdart-use-pattern-matching
Use switch expressions and pattern matching where appropriate
2.1Kdart-resolve-package-conflicts
Workflow for fixing package version conflicts. Use this when `pub get` fails due to incompatible package versions.
2.0Kdart-collect-coverage
Collect coverage using the coverage packge and create an LCOV report
2.0Kdart-generate-test-mocks
Define and generate mock objects for external dependencies using `package:mockito` and `build_runner`. Use when unit testing classes that depend on complex external services like APIs or databases.
2.0K