Overview
The analyzer examines Dart code without running it, checking for:- Syntax errors
- Type errors
- Potential runtime errors
- Coding style violations
- Best practice recommendations
Usage
Basic Examples
Command-Line Options
Fatal Levels
Control which issue levels should cause the analyzer to exit with an error code:Output Formats
The analyzer supports multiple output formats:Advanced Options
Configuration
Configure the analyzer using ananalysis_options.yaml file at the root of your project:
Basic Configuration
analysis_options.yaml
Error Severity Levels
You can configure the severity of specific diagnostics:error- Treat as an error (blocks compilation)warning- Treat as a warninginfo- Treat as an informational messageignore- Suppress the diagnostic
analysis_options.yaml
Excluding Files and Directories
Exclude files from analysis:analysis_options.yaml
Language Features
Enable strict mode features:analysis_options.yaml
Strong Mode
Configure strong mode options (Dart 2.0+):analysis_options.yaml
Linter Rules
The analyzer includes a comprehensive set of lint rules. Enable rules inanalysis_options.yaml:
Recommended Rules
Use a curated set of recommended rules:analysis_options.yaml
Core Lints
Use the core lints package:analysis_options.yaml
Custom Rule Configuration
analysis_options.yaml
Disable Specific Rules
analysis_options.yaml
Output Examples
Default Output
JSON Output
Machine Output
Suppressing Diagnostics
In Code
Suppress specific diagnostics using comments:Multiple Diagnostics
File-Level Suppression
Exit Codes
0- No issues found1- Issues found (errors or warnings, depending on configuration)3- Analysis completed with fatal issues
Integration
CI/CD Integration
ci.sh
Pre-commit Hook
.git/hooks/pre-commit
Editor Integration
Most editors integrate with the Dart analyzer through the Dart Analysis Server:- VS Code: Install the Dart extension
- IntelliJ/Android Studio: Built-in Dart plugin
- Vim/Neovim: Use vim-lsc or coc-flutter
- Emacs: Use lsp-mode with lsp-dart
Common Diagnostic Codes
Compile-Time Errors
undefined_name- Reference to undefined identifierundefined_method- Call to undefined methodinvalid_assignment- Type mismatch in assignmentargument_type_not_assignable- Wrong argument type
Warnings
unused_import- Import statement is unusedunused_local_variable- Local variable is never readdead_code- Unreachable code detecteddeprecated_member_use- Use of deprecated API
Hints/Info
unnecessary_cast- Explicit cast is redundantunnecessary_null_comparison- Null check is unnecessaryprefer_const_constructors- Constructor could be const
Performance Tuning
Cache Location
Set a custom cache directory to improve performance:Incremental Analysis
The analyzer uses incremental analysis by default, only re-analyzing changed files.Troubleshooting
Clear Analysis Cache
If you encounter issues, try clearing the analysis cache:Verbose Output
Enable verbose output for debugging:See Also
- Linter Rules - Complete list of available linter rules
- Diagnostic Messages - All diagnostic codes and messages
- analysis_options.yaml - Configuration file reference