This package provides a low-level library that performs static analysis of Dart code. It is useful for tool integration and embedding.
End-users should use the dartanalyzer command-line tool to analyze their Dart code.
Integrators that want to add Dart support to their editor should use the Dart Analysis Server. The Analysis Server API Specification is available. If you are adding Dart support to an editor or IDE, please let us know by emailing our list.
Both dartanalyzer and Dart Analysis Server can be configured with an
analysis_options.yaml file (using an .analysis_options file is deprecated).
This YAML file can control which files and paths are analyzed,
which lints are applied, and more.
If you are embedding the analyzer library in your project, you are responsible for finding the analysis options file, parsing it, and configuring the analyzer.
The analysis options file should live at the root of your project (for example,
next to your pubspec.yaml). Different embedders of analyzer, such as
dartanalyzer or Dart Analysis Server, may choose to find the file in various
different ways. Consult their documentation to learn more.
Here is an example file that instructs the analyzer to ignore two files:
analyzer:
exclude:
- test/_data/p4/lib/lib1.dart
- test/_data/p5/p5.dart
- test/_data/bad*.dart
- test/_brokendata/**
Note that you can use globs, as defined by the glob package.
Here is an example file that enables two lint rules:
linter:
rules:
- camel_case_types
- empty_constructor_bodies
Check out all the available Dart lint rules.
You can combine the analyzer section and the linter section into a single
configuration. Here is an example:
analyzer:
exclude:
- test/_data/p4/lib/lib1.dart
linter:
rules:
- camel_case_types
For more information, see the docs for customizing static analysis.
Many tools embed this library, such as:
Post issues and feature requests at https://github.com/dart-lang/sdk/issues
Questions and discussions are welcome at the Dart Analyzer Discussion Group.
The APIs in this package are, quite frankly, a mess at the moment. They were originally machine generated by a translator and were based on an earlier Java implementation. Several of the API's still look like their Java predecessors (or worse) rather than clean Dart API's.
In addition, there is currently no clean distinction between public and internal APIs. We plan to address this issue but doing so will, unfortunately, require a large number of breaking changes. We will try to minimize the pain this causes for our clients, but some pain is inevitable.
See the LICENSE file.
Expression.precendence to Precedence. Clients
that prepared for this change by switching to Expression.precedence2 should
now return to using Expression.precedence.ForEachStatement (use ForStatement instead)MapLiteral and MapLiteral2 (use SetOrMapLiteral instead)SetLiteral and SetLiteral2 (use SetOrMapLiteral instead)ListLiteral2 (use ListLiteral instead)ForStatement2 (use ForStatement instead)visitForEachStatement (override visitForStatement instead)visitMapLiteral and visitMapLiteral2 (override visitSetOrMapLiteral
instead)visitSetLiteral and visitSetLiteral2 (override visitSetOrMapLiteral
instead)visitListLiteral2 (override visitListLiteral instead)visitForStatement2 visit method (use VisitForStatement
instead)mapLiteral and mapLiteral2 (use setOrMapLiteral instead)setLiteral and setLiteral2 (use setOrMapLiteral instead)listLiteral2 (use listLiteral instead)AstFactory.forStatement2, and introduced
AstFactory.forStatement to replace itListLiteral.elements to
NodeList<CollectionElement>ListLiteral.elements2 (use ListLiteral.elements instead)SetOrMapLiteral.elements2, and introduced
SetOrMapLiteral.elements to replace itNodeLintRegistry.addForStatement2 (use
NodeLintRegistry.addForStatement instead)ForEachStatement (use ForStatement2 instead)ForStatement (use ForStatement2 instead)MapLiteral (use SetOrMapLiteral instead)SetLiteral (use SetOrMapLiteral instead)visitForEachStatement (override visitForStatement2 instead)visitForStatement (override visitForStatement2 instead)visitMapLiteral (override visitSetOrMapLiteral instead)visitSetLiteral (override visitSetOrMapLiteral instead)mapLiteral and mapLiteral2 (use setOrMapLiteral instead)setLiteral and setLiteral2 (use setOrMapLiteral instead)package:html (see #35802)ForEachStatement (use ForStatement2 instead)ForStatement (use ForStatement2 instead)MapLiteral (use SetOrMapLiteral instead)SetLiteral (use SetOrMapLiteral instead)Expression.precedence. In analyzer version 0.36.0, its return
type will be changed to Precedence. Clients that wish to prepare for the
change can switch to Expression.precedence2.AstFactory.mapLiteral2 and AstFactory.setLiteral2 (replaced by
AstFactory.setOrMapLiteral).AstVisitor.visitListLiteral2 (clients should not need to override this
anymore).AstVisitor.visitMapLiteral2 and AstVisitor.visitSetLiteral2 (replaced by
AstVisitor.visitSetOrMapLiteral).InheritanceManager class is now deprecated. The new
InheritanceManager2 class now supports accessing inherited interface/class
maps.AstVisitor, which will need to be implemented by any classes that implement
AstVisitor directly. Concrete implementations were added to other visitor
classes (such as RecursiveAstVisitor) so that clients that extend those
other classes will not be impacted.EMPTY_LIST constants. Please use const <...>[] instead.AnalysisSession
API.StrongTypeSystemImpl. Please use Dart2TypeSystem instead.@checked annotation. Please use the covariant
keyword instead (#28797).@literal:
NON_CONST_CALL_TO_LITERAL_CONSTRUCTOR.UriResolver documentation alerting clients of an
upcoming breaking change.declarations-casts has been removed and the implicit-casts
option now has the combined semantics of both options. This means that users
that disable implicit-casts might now see errors that were not previously
being reported.UriResolver documentation alerting clients of an
upcoming breaking change.AstNode.getAncestor and introduced
AstNode.thisOrAncestorMatching as its replacement.AnalysisOptions.strongMode flag. This is now hard-coded to
always return true.const A(B()) if B is non-const).analyzer.dart's parseCompilationUnit().@isTest annotations (from package:meta)
to the methods in their package which define a test.@isTest
void myMagicTest(String name, FutureOr Function() body) {
test(name, body);
}
When subscribed to notifications for outlines of a test file, they will include elements for UNIT_TEST_GROUP and UNIT_TEST_TEST.
TOP_LEVEL_CYCLE to an error._InternalLinkedHashMap is not a subtype of HashMap
in sdk 2.0.0-dev.22.0.NOTE This release was pulled from the package site due to an invalid SDK
constraint that was fixed in 0.31.0+1.
A number of updates, including support for the new Function syntax.
null in the event that the given path is not part of a BazelWorkspace.astFactory, located in package:analyzer/dart/ast/standard_ast_factory.dart.Element.docRange.1.20.0-dev.1.0 SDK.1.18.0-dev.4.0 SDK._embedder.yaml discovery and processing.configureContext() extracted from server).AnalysisContext API for associating configuration data with contexts
(setConfigurationData() and getConfigurationData()).OptionsProcessor extension point API changed to pass associated
AnalysisContext instance into the optionsProcessed call-back.ErrorHandler typedef API fix..analysis_options..packages files (issue 24126)UriResolver.resolveUri(..) now takes an optional actualUri.ResolutionCopier.visitAwaitExpression to copy *Type fields.ClassName?.staticMember to match spec.UriResolver.resolveUri(..) that did not
properly handle the new actualUri argument.dart:sdk extension .sdkext changed to _sdkext (to play nicer with pub).dart:sdk extensions from .sdkext..packages support.analyzer_cli package. Files moved:bin/analyzer.dartlib/options.dartlib/src/analyzer_impl.dartlib/src/error_formatter.dartargs package.New API:
Source.uri added.
Breaking changes:
DartSdk.fromEncoding replaced with fromFileUri.
Source.resolveRelative replaced with resolveRelativeUri.
Add this to your package's pubspec.yaml file:
dependencies:
analyzer: ^0.36.0
You can install packages from the command line:
with pub:
$ pub get
with Flutter:
$ flutter packages get
Alternatively, your editor might support pub get or flutter packages get.
Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:analyzer/analyzer.dart';
| Version | Uploaded | Documentation | Archive |
|---|---|---|---|
| 0.36.0 | Mar 21, 2019 |
|
|
| 0.35.4 | Mar 15, 2019 |
|
|
| 0.35.3 | Feb 28, 2019 |
|
|
| 0.35.2 | Feb 22, 2019 |
|
|
| 0.35.1 | Feb 12, 2019 |
|
|
| 0.35.0 | Jan 29, 2019 |
|
|
| 0.34.3 | Feb 1, 2019 |
|
|
| 0.34.2 | Jan 16, 2019 |
|
|
| 0.34.1 | Dec 19, 2018 |
|
|
| 0.34.0 | Nov 29, 2018 |
|
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
97
|
|
Health:
Code health derived from static analysis.
[more]
|
0
|
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
70
|
|
Overall:
Weighted score of the above.
[more]
|
62
|
We analyzed this package on Mar 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter, other
Primary library:
package:analyzer/analyzer.dartwith components:io.
Fix lib/src/summary/format.dart. (-98.73 points)
Analysis of lib/src/summary/format.dart reported 871 hints, including:
line 323 col 3: Avoid return types on setters.
line 332 col 3: Avoid return types on setters.
line 340 col 3: Avoid return types on setters.
line 348 col 3: Avoid return types on setters.
line 362 col 3: Prefer using /// for doc comments.
Fix lib/dart/ast/ast.dart. (-83.30 points)
Analysis of lib/dart/ast/ast.dart reported 357 hints, including:
line 73 col 3: Avoid return types on setters.
line 102 col 3: Avoid return types on setters.
line 108 col 3: Avoid return types on setters.
line 115 col 3: Avoid return types on setters.
line 123 col 3: Avoid return types on setters.
Fix lib/src/generated/engine.dart. (-81.07 points)
Analysis of lib/src/generated/engine.dart reported 332 hints, including:
line 42 col 1: Prefer using /// for doc comments.
line 48 col 1: Prefer using /// for doc comments.
line 88 col 3: Prefer using /// for doc comments.
line 94 col 3: Prefer using /// for doc comments.
line 100 col 3: Prefer using /// for doc comments.
Fix additional 187 files with analysis or formatting issues. (-1900.61 points)
Additional issues in the following files:
lib/src/error/codes.dart (326 hints)lib/src/generated/error_verifier.dart (195 hints)lib/src/dart/ast/ast.dart (189 hints)lib/src/dart/analysis/driver.dart (156 hints)lib/src/dart/element/element.dart (155 hints)lib/src/dart/constant/value.dart (142 hints)lib/src/context/cache.dart (137 hints)lib/dart/ast/ast_factory.dart (130 hints)lib/src/dart/element/type.dart (129 hints)lib/src/generated/parser.dart (125 hints)lib/src/dart/resolver/scope.dart (95 hints)lib/src/task/api/model.dart (95 hints)lib/src/dart/ast/utilities.dart (93 hints)lib/src/task/inputs.dart (79 hints)lib/src/generated/source.dart (78 hints)lib/src/dart/constant/evaluation.dart (76 hints)lib/dart/element/type.dart (72 hints)lib/src/dart/analysis/file_state.dart (72 hints)lib/src/dart/error/hint_codes.dart (71 hints)lib/src/generated/static_type_analyzer.dart (71 hints)lib/src/generated/sdk.dart (70 hints)lib/src/summary/resynthesize.dart (70 hints)lib/src/summary/flat_buffers.dart (69 hints)lib/src/dart/sdk/sdk.dart (67 hints)lib/src/task/driver.dart (62 hints)lib/src/generated/element_resolver.dart (55 hints)lib/src/dart/element/handle.dart (53 hints)lib/src/context/builder.dart (52 hints)lib/src/dart/analysis/index.dart (49 hints)lib/src/dart/element/builder.dart (47 hints)lib/src/dart/resolver/inheritance_manager.dart (47 hints)lib/src/summary/prelink.dart (46 hints)lib/instrumentation/instrumentation.dart (45 hints)lib/src/dart/analysis/search.dart (42 hints)lib/src/dart/element/member.dart (39 hints)lib/src/generated/source_io.dart (38 hints)lib/src/generated/testing/test_type_provider.dart (38 hints)lib/src/generated/type_system.dart (38 hints)lib/dart/ast/resolution_map.dart (37 hints)lib/file_system/file_system.dart (37 hints)lib/src/generated/utilities_collection.dart (33 hints)lib/src/context/context.dart (31 hints)lib/src/dart/analysis/context_locator.dart (30 hints)lib/src/generated/resolver.dart (30 hints)lib/src/task/strong_mode.dart (28 hints)lib/error/listener.dart (27 hints)lib/src/dart/analysis/file_tracker.dart (27 hints)lib/src/summary/link.dart (26 hints)lib/file_system/overlay_file_system.dart (23 hints)lib/src/generated/utilities_general.dart (23 hints)lib/src/task/strong/checker.dart (23 hints)lib/src/analysis_options/error/option_codes.dart (22 hints)lib/src/summary/package_bundle_reader.dart (22 hints)lib/dart/ast/visitor.dart (21 hints)lib/src/task/model.dart (21 hints)lib/src/cancelable_future.dart (20 hints)lib/error/error.dart (18 hints)lib/src/generated/sdk_io.dart (18 hints)lib/src/workspace/package_build.dart (18 hints)lib/dart/analysis/context_locator.dart (17 hints)lib/source/source_range.dart (17 hints)lib/src/dart/analysis/library_analyzer.dart (17 hints)lib/src/generated/parser_fasta.dart (17 hints)lib/src/workspace/gn.dart (17 hints)lib/src/dart/analysis/status.dart (16 hints)lib/src/summary/api_signature.dart (16 hints)lib/src/task/api/dart.dart (16 hints)lib/src/dart/error/syntactic_errors.dart (15 hints)lib/src/pubspec/pubspec_validator.dart (15 hints)lib/src/workspace/bazel.dart (15 hints)lib/dart/constant/value.dart (14 hints)lib/file_system/memory_file_system.dart (13 hints)lib/file_system/physical_file_system.dart (13 hints)lib/src/task/manager.dart (13 hints)lib/source/line_info.dart (12 hints)lib/dart/analysis/context_root.dart (11 hints)lib/dart/analysis/declared_variables.dart (11 hints)lib/src/pubspec/pubspec_warning_code.dart (11 hints)lib/src/source/source_resource.dart (11 hints)lib/exception/exception.dart (10 hints)lib/src/command_line/arguments.dart (10 hints)lib/src/context/source.dart (10 hints)lib/src/dart/analysis/file_byte_store.dart (10 hints)lib/src/dart/constant/utilities.dart (10 hints)lib/src/lint/linter.dart (10 hints)lib/src/summary/name_filter.dart (10 hints)lib/src/task/yaml.dart (10 hints)lib/src/error/pending_error.dart (9 hints)lib/src/generated/testing/ast_test_factory.dart (9 hints)lib/src/summary/base.dart (9 hints)lib/src/util/glob.dart (9 hints)lib/analyzer.dart (8 hints)lib/dart/analysis/analysis_context.dart (8 hints)lib/src/context/context_root.dart (8 hints)lib/src/dart/analysis/session.dart (8 hints)lib/src/dart/scanner/scanner.dart (8 hints)lib/src/lint/registry.dart (8 hints)lib/src/task/general.dart (8 hints)lib/src/workspace/workspace.dart (8 hints)lib/src/dart/sdk/patch.dart (7 hints)lib/src/generated/incremental_resolver.dart (7 hints)lib/src/generated/utilities_dart.dart (7 hints)lib/src/html/error/html_codes.dart (7 hints)lib/src/summary/summary_sdk.dart (7 hints)lib/src/dart/analysis/byte_store.dart (6 hints)lib/src/dart/analysis/context_builder.dart (6 hints)lib/src/dart/analysis/top_level_declaration.dart (6 hints)lib/src/dart/scanner/reader.dart (6 hints)lib/src/generated/java_engine.dart (6 hints)lib/src/source/package_map_resolver.dart (6 hints)lib/src/summary/expr_builder.dart (6 hints)lib/src/dart/analysis/context_root.dart (5 hints)lib/src/dart/analysis/library_context.dart (5 hints)lib/src/source/package_map_provider.dart (5 hints)lib/src/test_utilities/mock_sdk.dart (5 hints)lib/src/util/lru_map.dart (5 hints)lib/dart/element/visitor.dart (4 hints)lib/src/dart/analysis/driver_based_analysis_context.dart (4 hints)lib/src/dart/element/inheritance_manager2.dart (4 hints)lib/src/dart/error/todo_codes.dart (4 hints)lib/src/generated/constant.dart (4 hints)lib/src/generated/testing/element_factory.dart (4 hints)lib/src/generated/timestamped_data.dart (4 hints)lib/src/lint/analysis.dart (4 hints)lib/src/lint/config.dart (4 hints)lib/src/lint/options_rule_validator.dart (4 hints)lib/src/summary/summarize_ast.dart (4 hints)lib/src/summary/summarize_elements.dart (4 hints)lib/src/summary/summary_file_builder.dart (4 hints)lib/src/util/utilities_timing.dart (4 hints)lib/src/workspace/basic.dart (4 hints)lib/dart/analysis/context_builder.dart (3 hints)lib/dart/analysis/uri_converter.dart (3 hints)lib/src/analysis_options/analysis_options_provider.dart (3 hints)lib/src/dart/analysis/analysis_context_collection.dart (3 hints)lib/src/dart/analysis/defined_names.dart (3 hints)lib/src/dart/analysis/referenced_names.dart (3 hints)lib/src/dart/analysis/uri_converter.dart (3 hints)lib/src/dart/ast/constant_evaluator.dart (3 hints)lib/src/dart/resolver/flow_analysis.dart (3 hints)lib/src/fasta/ast_builder.dart (3 hints)lib/src/file_system/file_system.dart (3 hints)lib/src/generated/java_core.dart (3 hints)lib/src/string_source.dart (3 hints)lib/src/task/api/general.dart (3 hints)lib/src/dart/analysis/dependency/reference_collector.dart (2 hints)lib/src/dart/analysis/performance_logger.dart (2 hints)lib/src/dart/ast/ast_factory.dart (2 hints)lib/src/dart/constant/compute.dart (2 hints)lib/src/dart/constant/constant_verifier.dart (2 hints)lib/src/dart/error/lint_codes.dart (2 hints)lib/src/dart/resolver/method_invocation_resolver.dart (2 hints)lib/src/error/inheritance_override.dart (2 hints)lib/src/generated/interner.dart (2 hints)lib/src/services/available_declarations.dart (2 hints)lib/src/source/sdk_ext.dart (2 hints)lib/src/summary/public_namespace_computer.dart (2 hints)lib/src/summary/summarize_const_expr.dart (2 hints)lib/src/summary2/linked_element_factory.dart (2 hints)lib/src/task/api/yaml.dart (2 hints)lib/src/task/options.dart (2 hints)lib/dart/ast/standard_ast_factory.dart (1 hint)lib/dart/ast/standard_resolution_map.dart (1 hint)lib/instrumentation/file_instrumentation.dart (1 hint)lib/plugin/embedded_resolver_provider.dart (1 hint)lib/src/dart/analysis/cache.dart (1 hint)lib/src/dart/analysis/crc32.dart (1 hint)lib/src/dart/ast/resolution_map.dart (1 hint)lib/src/dart/ast/token.dart (1 hint)lib/src/dart/resolver/definite_assignment.dart (1 hint)lib/src/dart/resolver/exit_detector.dart (1 hint)lib/src/generated/ast.dart (1 hint)lib/src/generated/declaration_resolver.dart (1 hint)lib/src/generated/element.dart (1 hint)lib/src/generated/element_handle.dart (1 hint)lib/src/generated/java_io.dart (1 hint)lib/src/generated/testing/element_search.dart (1 hint)lib/src/generated/testing/node_search.dart (1 hint)lib/src/generated/testing/token_factory.dart (1 hint)lib/src/plugin/resolver_provider.dart (1 hint)lib/src/plugin/task.dart (1 hint)lib/src/services/lint.dart (1 hint)lib/src/summary2/tokens_context.dart (1 hint)lib/src/summary2/tokens_writer.dart (1 hint)lib/src/summary2/top_level_inference.dart (1 hint)lib/src/test_utilities/find_node.dart (1 hint)lib/src/util/asserts.dart (1 hint)The package description is too short. (-20 points)
Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.
Maintain an example. (-10 points)
Create a short demo in the example/ directory to show how to use this package.
Common filename patterns include main.dart, example.dart, and analyzer.dart. Packages with multiple examples should provide example/README.md.
For more information see the pub package layout conventions.
| Package | Constraint | Resolved | Available |
|---|---|---|---|
| Direct dependencies | |||
| Dart SDK | >=2.1.0-dev.5.0 <3.0.0 | ||
| args | >=0.12.1 <2.0.0 | 1.5.1 | |
| charcode | ^1.1.0 | 1.1.2 | |
| collection | ^1.10.1 | 1.14.11 | |
| convert | ^2.0.0 | 2.1.1 | |
| crypto | >=1.1.1 <3.0.0 | 2.0.6 | |
| front_end | 0.1.15 | 0.1.15 | |
| glob | ^1.0.3 | 1.1.7 | |
| kernel | 0.3.15 | 0.3.15 | |
| meta | ^1.0.2 | 1.1.7 | |
| package_config | >=0.1.5 <2.0.0 | 1.0.5 | |
| path | >=0.9.0 <2.0.0 | 1.6.2 | |
| pub_semver | ^1.4.2 | 1.4.2 | |
| source_span | ^1.2.0 | 1.5.5 | |
| watcher | >=0.9.6 <0.10.0 | 0.9.7+10 | |
| yaml | ^2.1.2 | 2.1.15 | |
| Transitive dependencies | |||
| async | 2.0.8 | ||
| string_scanner | 1.0.4 | ||
| term_glyph | 1.1.0 | ||
| typed_data | 1.1.6 | ||
| Dev dependencies | |||
| analysis_tool | |||
| test | ^1.0.0 | ||
| test_reflective_loader | ^0.1.8 | ||