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.
This package, lints
, contains the lint settings recommended by the Dart team.
Two sets of Dart 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.
Finally, a third set flutter_lints
extends the recommended set with additional recommended Flutter-specific 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 based on how many of the 'core' lints pass.
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/recommended.yaml
or:
include: package:lints/core.yaml
You can customize the predefined lint sets, both to disable one or more of the lints included, or to add additional lints. For details see customizing static analysis.
In migrating from the predefined lint sets provided by the package:pedantic
,
you get static analysis coverage from 29 additional lints. There are, however,
6 lints which the pedantic package includes which are not included in the
predefined lint sets provided by the lints package:
always_declare_return_types
, prefer_single_quotes
,
sort_child_properties_last
, unawaited_futures
, unsafe_html
, and
use_full_hex_values_for_flutter_colors
(also included in
package:flutter_lints
). To keep any of these lints enabled,
add them to your analysis options.
Additionally, package:pedantic
provides the unawaited
method for use with
unawaited_futures
. With SDK version 2.14 this method is available in the
dart:async
package, and this is now the recommended way to use it. Be sure to
mark the minimum SDK version of your package as 2.14
if you do so.
The Dart language changes and the ecosystem continues to develop new best practices, so the lint sets must be periodically updated to reflect the best way we know to write Dart code. The informal process we use is:
-
Anyone can file an issue to discuss a potential change to a lint set. (A change here means adding or removing a lint from one or both sets. If you want to discuss implementing an entirely new lint, the place to suggest that is at the linter repo.) Feedback is welcome from any Dart user.
-
Periodically, a group of Dart and Flutter team members meet to review the suggestions and decide what to adopt.
-
The lists are updated and a new version of the package is published.