The Dart linter is a static analyzer for identifying possible problems in your Dart source code. More than a hundred linter rules are available, checking anything from potential typing issues, coding style, and formatting.
The current package:lints
contains the official selections of lints that the
Dart team encourages using.
Two sets of lints are available:
-
Core lints: Lints that help identify critical issues that are likely to lead to problems when running or consuming Dart code. All code should pass these lints.
-
Recommended lints: Lints that help identify additional issues that may lead to problems when running or consuming Dart code, and lints that enforce writing Dart using a single, idiomatic style and format. All code is encouraged to pass these lints. The recommended lints include all the core lints.
When creating new Dart project using the dart create
command,
the lints from package:lints
are enabled by default.
When uploading a package to the pub.dev package repository, packages are awarded pub points depending on whether they pass at least the 'core' lints (note: the recommended lints automatically include all core lints).
For documentation on the individual lints, see the linter rules page on dart.dev.
For new apps created with dart create
, the lints are enabled by default.
For existing apps or packages, take these steps to enable these lints:
- In a terminal, located at the root of your package, run this command:
dart pub add --dev lints
- Create a new
analysis_options.yaml
file, next to the pubspec, that includes the lints package:
include: package:lints/core.yaml
You can customize the pre-defined lint sets, both to disable one or more of the lints included, or to add additional lints. For details see customizing static analysis.