|
| 1 | +[](https://github.com/dart-lang/lints/actions?query=branch%3Amain) |
| 2 | +[](https://pub.dev/packages/lints) |
| 3 | +[](https://pub.dev/packages/lints/publisher) |
| 4 | + |
| 5 | +# Official Dart lint rules |
| 6 | + |
| 7 | +The Dart linter is a static analyzer for identifying possible problems in your |
| 8 | +Dart source code. More than a hundred [linter rules][rules] are available, |
| 9 | +checking anything from potential typing issues, coding style, and formatting. |
| 10 | +This package - `package:lints` - contains the lint settings recommended by the |
| 11 | +Dart team. |
| 12 | + |
| 13 | +## Lint sets |
| 14 | + |
| 15 | +This package includes two sets of lints: |
| 16 | + |
| 17 | +* **Core lints**: Lints that help identify critical issues that are likely to |
| 18 | +lead to problems when running or consuming Dart code. All code should pass these |
| 19 | +lints. |
| 20 | + |
| 21 | +* **Recommended lints**: Lints that help identify additional issues that may |
| 22 | +lead to problems when running or consuming Dart code, and lints that enforce |
| 23 | +writing Dart using a single, idiomatic style and format. All code is encouraged |
| 24 | +to pass these lints. The recommended lints include all the core lints. |
| 25 | + |
| 26 | +Additionally, a third lint set - |
| 27 | +[`package:flutter_lints`](https://pub.dev/packages/flutter_lints) - extends the |
| 28 | +recommended set with additional recommended Flutter-specific lints. |
| 29 | + |
| 30 | +The Dart team will likely not provide recommendations past the `core` and |
| 31 | +`recommended` sets (e.g., a `strict` rule set). However, there are many such rule |
| 32 | +sets in the ecosystem (available at [pub.dev](https://pub.dev/)). |
| 33 | + |
| 34 | +Rule set authors: consider adding the `lints` topic to your pubspec to allow |
| 35 | +easier discovery (e.g., |
| 36 | +[pub.dev/packages?q=topic:lints](https://pub.dev/packages?q=topic%3Alints)). |
| 37 | +For more information about topics, visit |
| 38 | +[dart.dev/tools/pub/pubspec#topics](https://dart.dev/tools/pub/pubspec#topics). |
| 39 | + |
| 40 | +## Where these lints are used |
| 41 | + |
| 42 | +When creating a new Dart project using the [`dart create`][dart create] command, |
| 43 | +the `recommended` set of lints from `package:lints` is enabled by default. |
| 44 | + |
| 45 | +When uploading a package to the [pub.dev] package repository, packages are |
| 46 | +[awarded pub points][scoring] based on how many of the 'core' lints pass. |
| 47 | + |
| 48 | +## Enabling the lints |
| 49 | + |
| 50 | +For new apps created with `dart create` the `recommended` set of lints are |
| 51 | +enabled by default. |
| 52 | + |
| 53 | +For existing apps or packages, you can enable these lints via: |
| 54 | + |
| 55 | +1. In a terminal, located at the root of your package, run this command: |
| 56 | + |
| 57 | + ```terminal |
| 58 | + dart pub add dev:lints |
| 59 | + ``` |
| 60 | +
|
| 61 | +2. Create a new `analysis_options.yaml` file, next to the pubspec, that |
| 62 | + includes the lints package: |
| 63 | +
|
| 64 | + ```yaml |
| 65 | + include: package:lints/recommended.yaml |
| 66 | + ``` |
| 67 | +
|
| 68 | + or: |
| 69 | +
|
| 70 | + ```yaml |
| 71 | + include: package:lints/core.yaml |
| 72 | + ``` |
| 73 | +
|
| 74 | +## Upgrading to the latest lints |
| 75 | +
|
| 76 | +To upgrade to the latest version of the lint set, run: |
| 77 | +
|
| 78 | +``` |
| 79 | +dart pub add dev:lints |
| 80 | +``` |
| 81 | +
|
| 82 | +## Customizing the predefined lint sets |
| 83 | +
|
| 84 | +For details on customizing static analysis above and beyond the predefined |
| 85 | +lint sets, check out [Customizing static analysis]. |
| 86 | +
|
| 87 | +## Evolving the lint sets |
| 88 | +
|
| 89 | +The Dart language changes and the ecosystem continues to develop new best |
| 90 | +practices, so the lint sets must be periodically updated to reflect the best way |
| 91 | +we know to write Dart code. The process we use is: |
| 92 | +
|
| 93 | +1. Anyone can file an [issue] to discuss a potential change to a lint set |
| 94 | + (i.e., adding or removing a lint from one or both sets; if you're proposing |
| 95 | + an entirely new lint, the place to suggest that is at the [linter repo]). |
| 96 | + Feedback is welcome from any Dart user. |
| 97 | +
|
| 98 | +2. Periodically, a group of Dart and Flutter team members meet to review the |
| 99 | + suggestions and decide what to adopt. |
| 100 | +
|
| 101 | +3. The lists are updated and a new version of the package is published. |
| 102 | +
|
| 103 | +## Lint set contents |
| 104 | +
|
| 105 | +See [rules.md](https://github.com/dart-lang/lints/blob/main/rules.md) for a list |
| 106 | +of rules that make up the core and recommended rule sets. |
| 107 | +
|
| 108 | +[dart create]: https://dart.dev/tools/dart-create |
| 109 | +[scoring]: https://pub.dev/help/scoring |
| 110 | +[customizing static analysis]: https://dart.dev/tools/analysis |
| 111 | +[rules]: https://dart.dev/tools/linter-rules |
| 112 | +[pub.dev]: https://pub.dev |
| 113 | +[issue]: https://github.com/dart-lang/lints/issues |
| 114 | +[linter repo]: https://github.com/dart-lang/linter |
| 115 | +[`package:flutter_lints`]: https://pub.dev/packages/flutter_lints |
0 commit comments