Seth Ladd | 527c163 | 2015-10-20 11:32:28 -0700 | [diff] [blame] | 1 | # Analyzer for Dart |
pquitslund@google.com | 418d5ba | 2013-01-31 17:29:36 +0000 | [diff] [blame] | 2 | |
Devon Carew | 6e34c36 | 2019-07-18 23:06:26 +0000 | [diff] [blame] | 3 | This package provides a library that performs static analysis |
| 4 | of Dart code. It is useful for tool integration and embedding. |
pquitslund@google.com | 418d5ba | 2013-01-31 17:29:36 +0000 | [diff] [blame] | 5 | |
Kathy Walrath | b18de84 | 2018-12-07 21:29:42 +0000 | [diff] [blame] | 6 | End-users should use the [dartanalyzer][] command-line tool |
Seth Ladd | 527c163 | 2015-10-20 11:32:28 -0700 | [diff] [blame] | 7 | to analyze their Dart code. |
| 8 | |
| 9 | Integrators that want to add Dart support to their editor |
| 10 | should use the _Dart Analysis Server_. |
| 11 | The [Analysis Server API Specification][serverapi] is available. |
| 12 | If you are adding Dart support to an editor or IDE, please let us know |
| 13 | by emailing our [list][]. |
| 14 | |
| 15 | ## Configuring the analyzer |
| 16 | |
Dan Rubel | 4752b67 | 2017-05-03 11:54:35 -0400 | [diff] [blame] | 17 | Both `dartanalyzer` and Dart Analysis Server can be configured with an |
| 18 | `analysis_options.yaml` file (using an `.analysis_options` file is deprecated). |
| 19 | This YAML file can control which files and paths are analyzed, |
| 20 | which lints are applied, and more. |
Seth Ladd | 527c163 | 2015-10-20 11:32:28 -0700 | [diff] [blame] | 21 | |
Brian Wilkerson | 44836f8 | 2016-05-13 07:33:06 -0700 | [diff] [blame] | 22 | If you are embedding the analyzer library in your project, you are responsible |
| 23 | for finding the analysis options file, parsing it, and configuring the analyzer. |
Seth Ladd | 527c163 | 2015-10-20 11:32:28 -0700 | [diff] [blame] | 24 | |
Brian Wilkerson | 44836f8 | 2016-05-13 07:33:06 -0700 | [diff] [blame] | 25 | The analysis options file should live at the root of your project (for example, |
| 26 | next to your `pubspec.yaml`). Different embedders of analyzer, such as |
| 27 | `dartanalyzer` or Dart Analysis Server, may choose to find the file in various |
| 28 | different ways. Consult their documentation to learn more. |
Seth Ladd | 527c163 | 2015-10-20 11:32:28 -0700 | [diff] [blame] | 29 | |
Brian Wilkerson | 44836f8 | 2016-05-13 07:33:06 -0700 | [diff] [blame] | 30 | Here is an example file that instructs the analyzer to ignore two files: |
Seth Ladd | 527c163 | 2015-10-20 11:32:28 -0700 | [diff] [blame] | 31 | |
Kevin Moore | 9f74470 | 2016-03-02 17:10:50 -0800 | [diff] [blame] | 32 | ```yaml |
Seth Ladd | 527c163 | 2015-10-20 11:32:28 -0700 | [diff] [blame] | 33 | analyzer: |
| 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 | |
| 41 | Note that you can use globs, as defined by the [glob package][glob]. |
| 42 | |
Seth Ladd | 527c163 | 2015-10-20 11:32:28 -0700 | [diff] [blame] | 43 | Here is an example file that enables two lint rules: |
| 44 | |
Kevin Moore | 9f74470 | 2016-03-02 17:10:50 -0800 | [diff] [blame] | 45 | ```yaml |
Seth Ladd | 527c163 | 2015-10-20 11:32:28 -0700 | [diff] [blame] | 46 | linter: |
| 47 | rules: |
| 48 | - camel_case_types |
| 49 | - empty_constructor_bodies |
| 50 | ``` |
| 51 | |
| 52 | Check out all the available [Dart lint rules][lintrules]. |
| 53 | |
| 54 | You can combine the `analyzer` section and the `linter` section into a single |
| 55 | configuration. Here is an example: |
| 56 | |
Kevin Moore | 9f74470 | 2016-03-02 17:10:50 -0800 | [diff] [blame] | 57 | ```yaml |
Seth Ladd | 527c163 | 2015-10-20 11:32:28 -0700 | [diff] [blame] | 58 | analyzer: |
| 59 | exclude: |
| 60 | - test/_data/p4/lib/lib1.dart |
| 61 | linter: |
| 62 | rules: |
| 63 | - camel_case_types |
| 64 | ``` |
| 65 | |
pq | 118bdcc | 2019-01-30 18:01:04 +0000 | [diff] [blame] | 66 | For more information, see the docs for |
| 67 | [customizing static analysis][custom_analysis]. |
| 68 | |
Seth Ladd | 527c163 | 2015-10-20 11:32:28 -0700 | [diff] [blame] | 69 | ## Who uses this library? |
| 70 | |
| 71 | Many tools embed this library, such as: |
| 72 | |
Robert Nystrom | 5fbde4d | 2021-10-01 04:41:04 +0000 | [diff] [blame] | 73 | * [dart format] - a formatter for Dart code |
Kevin Moore | 9f74470 | 2016-03-02 17:10:50 -0800 | [diff] [blame] | 74 | * [dartdoc] - a documentation generator for Dart code |
| 75 | * [Dart Analysis Server][analysis_sever] - a stateful server that supports IDEs and editors |
Seth Ladd | 527c163 | 2015-10-20 11:32:28 -0700 | [diff] [blame] | 76 | |
| 77 | ## Support |
| 78 | |
Kevin Moore | 9f74470 | 2016-03-02 17:10:50 -0800 | [diff] [blame] | 79 | Post issues and feature requests at https://github.com/dart-lang/sdk/issues |
| 80 | |
| 81 | Questions and discussions are welcome at the |
| 82 | [Dart Analyzer Discussion Group][list]. |
Seth Ladd | 527c163 | 2015-10-20 11:32:28 -0700 | [diff] [blame] | 83 | |
| 84 | ## Background |
| 85 | |
Devon Carew | 6e34c36 | 2019-07-18 23:06:26 +0000 | [diff] [blame] | 86 | The APIs in this package were originally machine generated by a translator and were |
| 87 | based on an earlier Java implementation. Several of the API's still look like their Java |
| 88 | predecessors rather than clean Dart APIs. |
brianwilkerson@google.com | 3d5426c | 2015-04-10 17:21:29 +0000 | [diff] [blame] | 89 | |
| 90 | In addition, there is currently no clean distinction between public and internal |
Devon Carew | 6e34c36 | 2019-07-18 23:06:26 +0000 | [diff] [blame] | 91 | APIs. We plan to address this issue but doing so will, unfortunately, require a |
| 92 | large number of breaking changes. We will try to minimize the pain this causes for |
| 93 | our clients, but some pain is inevitable. |
brianwilkerson@google.com | 3d5426c | 2015-04-10 17:21:29 +0000 | [diff] [blame] | 94 | |
Seth Ladd | 527c163 | 2015-10-20 11:32:28 -0700 | [diff] [blame] | 95 | ## License |
| 96 | |
Kevin Moore | 9f74470 | 2016-03-02 17:10:50 -0800 | [diff] [blame] | 97 | See the [LICENSE] file. |
Seth Ladd | 527c163 | 2015-10-20 11:32:28 -0700 | [diff] [blame] | 98 | |
pq | dd35db6 | 2021-09-09 18:14:36 +0000 | [diff] [blame] | 99 | [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 Ladd | 527c163 | 2015-10-20 11:32:28 -0700 | [diff] [blame] | 101 | [list]: https://groups.google.com/a/dartlang.org/forum/#!forum/analyzer-discuss |
pq | ca70671 | 2018-12-11 23:02:34 +0000 | [diff] [blame] | 102 | [lintrules]: https://dart-lang.github.io/linter/lints/ |
Kevin Moore | 8342ec2 | 2019-11-20 11:30:48 +0000 | [diff] [blame] | 103 | [glob]: https://pub.dev/packages/glob |
pq | dd35db6 | 2021-09-09 18:14:36 +0000 | [diff] [blame] | 104 | [LICENSE]: https://github.com/dart-lang/sdk/blob/main/pkg/analyzer/LICENSE |
Robert Nystrom | 5fbde4d | 2021-10-01 04:41:04 +0000 | [diff] [blame] | 105 | [dart format]: https://github.com/dart-lang/dart_style |
Kevin Moore | 9f74470 | 2016-03-02 17:10:50 -0800 | [diff] [blame] | 106 | [dartdoc]: https://github.com/dart-lang/dartdoc |
pq | dd35db6 | 2021-09-09 18:14:36 +0000 | [diff] [blame] | 107 | [analysis_sever]: https://github.com/dart-lang/sdk/tree/main/pkg/analysis_server |
Kevin Moore | 0acc564 | 2020-05-13 18:24:12 +0000 | [diff] [blame] | 108 | [custom_analysis]: https://dart.dev/guides/language/analysis-options |