blob: d35c78b06d6116778496ffc0060e2fe8ce569097 [file] [log] [blame] [view]
Seth Ladd527c1632015-10-20 11:32:28 -07001# Analyzer for Dart
pquitslund@google.com418d5ba2013-01-31 17:29:36 +00002
Devon Carew6e34c362019-07-18 23:06:26 +00003This package provides a library that performs static analysis
4of Dart code. It is useful for tool integration and embedding.
pquitslund@google.com418d5ba2013-01-31 17:29:36 +00005
Kathy Walrathb18de842018-12-07 21:29:42 +00006End-users should use the [dartanalyzer][] command-line tool
Seth Ladd527c1632015-10-20 11:32:28 -07007to analyze their Dart code.
8
9Integrators that want to add Dart support to their editor
10should use the _Dart Analysis Server_.
11The [Analysis Server API Specification][serverapi] is available.
12If you are adding Dart support to an editor or IDE, please let us know
13by emailing our [list][].
14
15## Configuring the analyzer
16
Dan Rubel4752b672017-05-03 11:54:35 -040017Both `dartanalyzer` and Dart Analysis Server can be configured with an
18`analysis_options.yaml` file (using an `.analysis_options` file is deprecated).
19This YAML file can control which files and paths are analyzed,
20which lints are applied, and more.
Seth Ladd527c1632015-10-20 11:32:28 -070021
Brian Wilkerson44836f82016-05-13 07:33:06 -070022If you are embedding the analyzer library in your project, you are responsible
23for finding the analysis options file, parsing it, and configuring the analyzer.
Seth Ladd527c1632015-10-20 11:32:28 -070024
Brian Wilkerson44836f82016-05-13 07:33:06 -070025The analysis options file should live at the root of your project (for example,
26next to your `pubspec.yaml`). Different embedders of analyzer, such as
27`dartanalyzer` or Dart Analysis Server, may choose to find the file in various
28different ways. Consult their documentation to learn more.
Seth Ladd527c1632015-10-20 11:32:28 -070029
Brian Wilkerson44836f82016-05-13 07:33:06 -070030Here is an example file that instructs the analyzer to ignore two files:
Seth Ladd527c1632015-10-20 11:32:28 -070031
Kevin Moore9f744702016-03-02 17:10:50 -080032```yaml
Seth Ladd527c1632015-10-20 11:32:28 -070033analyzer:
34 exclude:
35 - test/_data/p4/lib/lib1.dart
36 - test/_data/p5/p5.dart
37 - test/_data/bad*.dart
38 - test/_brokendata/**
39```
40
41Note that you can use globs, as defined by the [glob package][glob].
42
Seth Ladd527c1632015-10-20 11:32:28 -070043Here is an example file that enables two lint rules:
44
Kevin Moore9f744702016-03-02 17:10:50 -080045```yaml
Seth Ladd527c1632015-10-20 11:32:28 -070046linter:
47 rules:
48 - camel_case_types
49 - empty_constructor_bodies
50```
51
52Check out all the available [Dart lint rules][lintrules].
53
54You can combine the `analyzer` section and the `linter` section into a single
55configuration. Here is an example:
56
Kevin Moore9f744702016-03-02 17:10:50 -080057```yaml
Seth Ladd527c1632015-10-20 11:32:28 -070058analyzer:
59 exclude:
60 - test/_data/p4/lib/lib1.dart
61linter:
62 rules:
63 - camel_case_types
64```
65
pq118bdcc2019-01-30 18:01:04 +000066For more information, see the docs for
67[customizing static analysis][custom_analysis].
68
Seth Ladd527c1632015-10-20 11:32:28 -070069## Who uses this library?
70
71Many tools embed this library, such as:
72
Robert Nystrom5fbde4d2021-10-01 04:41:04 +000073* [dart format] - a formatter for Dart code
Kevin Moore9f744702016-03-02 17:10:50 -080074* [dartdoc] - a documentation generator for Dart code
75* [Dart Analysis Server][analysis_sever] - a stateful server that supports IDEs and editors
Seth Ladd527c1632015-10-20 11:32:28 -070076
77## Support
78
Kevin Moore9f744702016-03-02 17:10:50 -080079Post issues and feature requests at https://github.com/dart-lang/sdk/issues
80
81Questions and discussions are welcome at the
82[Dart Analyzer Discussion Group][list].
Seth Ladd527c1632015-10-20 11:32:28 -070083
84## Background
85
Devon Carew6e34c362019-07-18 23:06:26 +000086The APIs in this package were originally machine generated by a translator and were
87based on an earlier Java implementation. Several of the API's still look like their Java
88predecessors rather than clean Dart APIs.
brianwilkerson@google.com3d5426c2015-04-10 17:21:29 +000089
90In addition, there is currently no clean distinction between public and internal
Devon Carew6e34c362019-07-18 23:06:26 +000091APIs. We plan to address this issue but doing so will, unfortunately, require a
92large number of breaking changes. We will try to minimize the pain this causes for
93our clients, but some pain is inevitable.
brianwilkerson@google.com3d5426c2015-04-10 17:21:29 +000094
Seth Ladd527c1632015-10-20 11:32:28 -070095## License
96
Kevin Moore9f744702016-03-02 17:10:50 -080097See the [LICENSE] file.
Seth Ladd527c1632015-10-20 11:32:28 -070098
pqdd35db62021-09-09 18:14:36 +000099[serverapi]: https://htmlpreview.github.io/?https://github.com/dart-lang/sdk/blob/main/pkg/analysis_server/doc/api.html
100[dartanalyzer]: https://github.com/dart-lang/sdk/tree/main/pkg/analyzer_cli#dartanalyzer
Seth Ladd527c1632015-10-20 11:32:28 -0700101[list]: https://groups.google.com/a/dartlang.org/forum/#!forum/analyzer-discuss
pqca706712018-12-11 23:02:34 +0000102[lintrules]: https://dart-lang.github.io/linter/lints/
Kevin Moore8342ec22019-11-20 11:30:48 +0000103[glob]: https://pub.dev/packages/glob
pqdd35db62021-09-09 18:14:36 +0000104[LICENSE]: https://github.com/dart-lang/sdk/blob/main/pkg/analyzer/LICENSE
Robert Nystrom5fbde4d2021-10-01 04:41:04 +0000105[dart format]: https://github.com/dart-lang/dart_style
Kevin Moore9f744702016-03-02 17:10:50 -0800106[dartdoc]: https://github.com/dart-lang/dartdoc
pqdd35db62021-09-09 18:14:36 +0000107[analysis_sever]: https://github.com/dart-lang/sdk/tree/main/pkg/analysis_server
Kevin Moore0acc5642020-05-13 18:24:12 +0000108[custom_analysis]: https://dart.dev/guides/language/analysis-options