The Dart Linter package defines lint rules that identify and report on "lints" found in Dart code. Linting is performed by the Dart
analysis server and the dartanalyzer
commandline tool.
The linter is bundled with the Dart SDK; if you have an updated Dart SDK already, you're done!
Alternatively, if you want to contribute to the linter or examine the source, clone the linter
repo like this:
$ git clone https://github.com/dart-lang/linter.git
The linter gives you feedback to help you catch potential errors and keep your code in line with the published Dart Style Guide. Currently enforceable lint rules (or "lints") are catalogued here and can be configured via an analysis options file. The linter is run from within the dartanalyzer
command-line tool shipped with the Dart SDK. Assuming you have lints configured in an analysis_options.yaml
file with these contents:
linter:
rules:
- annotate_overrides
- hash_and_equals
- prefer_is_not_empty
you could lint your package like this:
$ dartanalyzer --options analysis_options.yaml .
and see any violations of the annotate_overrides
, hash_and_equals
, and prefer_is_not_empty
rules in the console. To help you choose the rules you want to enable for your package, we have provided a complete list of rules and a growing list of lints according to the Effective Dart guide. For the lints that are enforced internally at Google, see package:pedantic.
If a specific lint warning should be ignored, it can be flagged with a comment. For example,
// ignore: avoid_as
(pm as Person).firstName = 'Seth'
tells the dartanalyzer
to ignore this instance of avoid_as
warning. As lints are treated the same as errors and warnings by the analyzer, their severity can similarly be configured in an options file. For example, an analysis options file that specifies
linter:
rules:
- avoid_as
analyzer:
errors:
avoid_as: error
tells the analyzer to treat avoid_as
lints as errors. For more on configuring analysis see the analysis option file docs.
Feedback is, of course, greatly appreciated and contributions are welcome! Please read the contribution guidelines; mechanics of writing lints are covered here.
Please file feature requests and bugs in the issue tracker.
prefer_collection_literals
Set literal false positivesprefer_const_declarations
Set literal false positivesprovide_deprecation_message
prefer_collection_literals
to support Set literalssuper_goes_last
InheritanceManager2
APIunnecessary_parenthesis
updated to play nicer with cascadesuse_full_hex_values_for_flutter_colors
prefer_null_aware_operators
hash_and_equals
fixed to respect hashCode
fieldsprefer_final_locals
to ignore loop variables, andprefer_final_in_for_each
lint to handle the for each
caseprefer_final_locals
to check to for loop variablestype_annotate_public_apis
false positives on local functionsavoid_shadowing_type_parameters
to report shadowed type parameters in generic typedefsuse_setters_to_change_properties
to not wrongly lint overriding methodscascade_invocations
to not lint awaited targetsprefer_conditional_assignment
false positivesjoin_return_with_assignment
false positivescascade_invocations
false positivesinvariant_booleans
status to experimentalunnecessary_parenthesis
updated to allow wrapping a !
argumentalways_declare_return_types
prefer_final_fields
to work with classes that have generic type argumentsunrelated_type_equality_checks
^0.34.0
avoid_positional_boolean_parameters
, literal_only_boolean_expressions
, prefer_foreach
, prefer_void_to_null
promoted to stableunnecessary_parenthesis
improved to handle function expressionsprefer_bool_in_asserts
(redundant w/ Dart 2 checks)0.33.4
2.1.0
unnecessary_await_in_return
use_function_type_syntax_for_parameters
LinterContext
APIuse_setters_to_change_properties
prefer_foreach
and public_member_api_docs
avoid_returning_null_for_future
avoid_shadowing_type_parameters
prefer_int_literals
await_only_futures
to allow awaiting on null
use_setters_to_change_properties
to work with =>
short-handprefer_iterable_whereType
await_only_futures
null_closures
avoid_returning_null_for_void
^0.33.0
sort_constructors_first
to apply to all membersunnecessary_this
to work on field initializersunawaited_futures
to ignore assignments within cascadessort_pub_dependencies
prefer_mixin
avoid_implementing_value_types
flutter_style_todos
invariant_booleans
package:pedantic
unawaited_futures
avoid_void_async
unawaited_futures
updated to check cascadesvoid_checks
(allowing T Function()
to be assigned to void Function()
)lib/
lines_longer_than_80_chars
prefer_void_to_null
new
and const
to be compatible w/ VMs running --no-preview-dart-2
lines_longer_than_80_chars
to handle CRLF endingsnon_constant_identifier_names
to better handle invalid codecurly_braces_in_flow_control_structures
avoid_positional_boolean_parameters
to ignore overridden methodsprefer_is_empty
to not evaluate constants beyond int literalsnull_closures
lines_longer_than_80_chars
const
error handlinglinter
binary to use previewDart2
unnecessary_const
lintunnecessary_new
lintuse_to_and_as_if_applicable
file_names
lintunnecessary_statements
to ignore getters (as they may be side-effecting).void_checks
to handle arguments not resolved to a parameterprefer_const_literals_to_create_immutables
unrelated_type_equality_checks
now allows comparison between Int64
or Int32
and int
unnecessary_parenthesis
improved to handle cascades in cascadesNodeLintRule
and UnitLintRule
yielding significant performance gains all aroundprefer_final_fields
(~6x)void_checks
void_checks
lintavoid_field_initializers_in_const_classes
lintunnecessary_statements
avoid_js_rounded_ints
lintavoid_double_and_int_checks
lintprefer_const_declarations
avoid_types_as_parameter_names
prefer_iterable_whereType
lintprefer_generic_function_type_aliases
lintlibrary_prefixes
)avoid_bool_literals_in_conditional_expressions
lintprefer_equal_for_default_values
lintavoid_private_typedef_functions
lintavoid_single_cascade_in_expression_statements
lintinvariant_booleans
when analyzing for loops with no conditionavoid_types_as_parameter_names
lintavoid_renaming_method_parameters
lintavoid_relative_lib_imports
lintunnecessary_parenthesis
lintprefer_const_literals_to_create_immutables
to handle undefined classes gracefullyprefer_const_declarations
to support optional new
and const
prefer_const_declarations
updated to check localsinvariant_booleans
2.0.0-dev
prefer_const_declarations.dart
lintprefer_const_literals_to_create_immutables
lintavoid_unused_constructor_parameters
comment_references
args
package dependency to support versions 1.*
avoid_unused_constructor_parameters
updated to better handle redirecting factory constructorsavoid_returning_this
improvementsprefer_bool_in_asserts
improvementsprefer_interpolation_to_compose_strings
updated to allow concatenation of two non-literal stringsprefer_interpolation_to_compose_strings
updated to allow +=
prefer_const_constructors_in_immutables
false positive with redirecting factory constructorspublic_member_api_docs
fix for package URIsavoid_positional_boolean_parameters
updated to allow booleans in operator declarationscomment_references
fixed to handle incomplete referencesnon_constant_identifier_names
updated to allow underscores around numbersavoid_unused_constructor_parameters
lintprefer_bool_in_asserts
lintprefer_typing_uninitialized_variables
lintunnecessary_statements
lintpublic_member_api_docs
updated to only lint source in lib/
EmptyStatement
s$
s2.0.0-dev.infinity
constraint)non_constant_identifier_names
extended to include named constructors2.0.0-dev.infinity
prefer_final_fields
performanceunnecessary_overrides
(noSuchMethod
handling, return type narrowing, special casing of documented super
calls)non_constant_identifier_names
to handle identifiers with no nameprefer_const_constructors
to support list literalsrecursive_getters
cascade_invocations
prefer_const_constructors_in_immutables
lintalways_put_required_named_parameters_first
lintprefer_asserts_in_initializer_lists
lint--benchmark
modeprefer_single_quote_strings
lintavoid_setters_without_getters
directives_ordering
to work with part directives located after exportscascade_invocations
false positivesliteral_only_boolean_expressions
false positivescascade_invocations
only lints method invocations if target is a simple identifier use_string_buffers
false positivesprefer_const_constructors
-s
) output now sorted.prefer_foreach
lint.use_string_buffers
rule.unnecessary_overrides
rule.join_return_with_assignment_when_possible
rule.use_to_and_as_if_applicable
rule.avoid_setters_without_getters
rule.always_put_control_body_on_new_line
rule.avoid_positional_boolean_parameters
rule.always_require_non_null_named_parameters
rule.prefer_conditional_assignment
rule.avoid_types_on_closure_parameters
rule.always_put_control_body_on_new_line
rule.use_setters_to_change_properties
rule.avoid_returning_this
rule.avoid_annotating_with_dynamic_when_not_required
rule.prefer_constructors_over_static_methods
rule.avoid_returning_null
rule.avoid_classes_with_only_static_members
rule.avoid_null_checks_in_equality_operators
rule.avoid_catches_without_on_clauses
rule.avoid_catching_errors
rule.use_rethrow_when_possible
rule.prefer_final_fields
, unnecessary_lambdas
, await_only_futures
, cascade_invocations
, avoid_types_on_closure_parameters
, and overridden_fields
).prefer_interpolation_to_compose_strings
.unnecessary_this
rule.prefer_initializing_formals
rule.avoid_function_literals_in_foreach_calls
lint.avoid_slow_async_io
lint.cascade_invocations
lint.directives_ordering
lint.no_adjacent_strings_in_list
lint.no_duplicate_case_values
lint.omit_local_variable_types
lint.prefer_adjacent_string_concatenation
lint.prefer_collection_literals
lint.prefer_const_constructors
lint.prefer_contains
lint.prefer_expression_function_bodies
lint.prefer_function_declarations_over_variables
lint.prefer_initializing_formals
lint.prefer_interpolation_to_compose_strings
lint.prefer_is_empty
lint.recursive_getters
lint.unnecessary_brace_in_string_interps
lint.unnecessary_lambdas
lint.unnecessary_null_aware_assignments
lint.unnecessary_null_in_if_null_operators
lint.cascade_invocations
lint.await_only_futures
to accept classes that extend or implement Future
.$
s.parameter_assignments
(improved getter handling and an NPE).dart_type_utilities
(dart-lang/sdk#27405).parameter_assignments
lint.prefer_final_fields
lint.prefer_final_locals
lint.solo_debug
(#304).test
(#302).[]=
in always_declare_return_types
(#300).invariant_booleans
lint.literal_only_boolean_expressions
lint.camel_case_types
to allow $
in identifiers (#290).close_sinks
to respect calls to destroy
(#282).only_throw_errors
to report on the expression not node.whitespace_around_ops
pending re-name and re-design (#249).rule:rule_name
and docs:location
) for rule stub and doc generation (respectively).non_constant_identifier_names
.valid_regexps
lint (#277).whitespace_around_ops
lint (#249).overridden_fields
to flag overridden static fields (#274).list_remove_unrelated_type
to detect passing a non-T
value to `List.remove()`` (#271).empty_catches
lint to catch empty catch blocks (#43).close_sinks
false positive (#268).linter
support for --strong
to allow for running linter in strong mode.only_throw_errors
lint.empty_statements
(#259).iterable_contains_unrelated_type
(#267).cancel_subscriptions
lint.close_sinks
lint.iterable_contains_unrelated_type
.iterable_contains_unrelated_type
(#245).comment_references
error description.overriden_field
false positive (#246).lints
option to rules
(#248).public_member_api_docs
to check for documented getters when checking setters (#237).iterable_contains_unrelated_type
lint to detect when Iterable.contains
is invoked with an object of an unrelated type.comment_references
lint to ensure identifiers referenced in docs are in scope (#240).overriden_field
s.unrelated_type_equality_checks
lint.$
identifiers in string interpolation lint (#214).plugin
API (0.2.0
).is
checks (#227).const
and final
vars to be initialized to null (#210).empty_constructor_bodies
(#209).main
when checking for API docs (#207).$
in type names (#220).test_types_in_equals
lint.await_only_futures
lint.throw_in_finally
lint.control_flow_in_finally
lint.@optionalTypeArgs
(#196).public_member_api_docs
).annotate_overrides
, public_member_api_docs
).LibraryNames
regexp that in pathological cases went exponential.hashCode
and ==
(#168).null
(#160).analyzer
0.27.0
.type_annotate_public_apis
to properly handle getters/setters (#151; dart-lang/sdk#25092).avoid_empty_else
lint rule (dart-lang/sdk#224936).package_api_docs
(dart-lang/sdk#24947; #154).package_prefixed_library_names
(dart-lang/sdk#24947; #154).prefer_is_not_empty
lint rule (#143).type_annotate_public_apis
lint rule (#24).avoid_as
lint rule (#145).non_constant_identifier_names
rule to special case underscore identifiers in callbacks._
s in callback type validation (addresses false positives in always_specify_types
) (#147).always_declare_return_types
lint rule (#146).always_specify_types
to detect missing types in declared identifiers and narrowed source range to the token.implementation_imports
lint rule (#33).always_specify_types
lint rule (#144).unnecessary_brace_in_string_interp
lint. Fix #112.lib/
to use a package:
URI. Fix #49.analyzer
package constraints.one_member_abstracts
lint. Fix #64.example/readme.md
Some example analysis options files.
For more on lint rule sets see the analyzer docs on customizing static analysis.
For a canonical set of rules used internally at Google and by an increasing number of tools, see
package:pedantic
.
Add this to your package's pubspec.yaml file:
dependencies:
linter: ^0.1.82
You can install packages from the command line:
with pub:
$ pub get
with Flutter:
$ flutter packages get
Alternatively, your editor might support pub get
or flutter packages get
.
Check the docs for your editor to learn more.
Version | Uploaded | Documentation | Archive |
---|---|---|---|
0.1.82 | Feb 12, 2019 |
|
|
0.1.81 | Feb 10, 2019 |
|
|
0.1.80 | Feb 8, 2019 |
|
|
0.1.79 | Jan 25, 2019 |
|
|
0.1.78 | Jan 4, 2019 |
|
|
0.1.77 | Jan 3, 2019 |
|
|
0.1.76 | Dec 14, 2018 |
|
|
0.1.75 | Dec 4, 2018 |
|
|
0.1.74 | Dec 4, 2018 |
|
|
0.1.73 | Nov 27, 2018 |
|
|
Popularity:
Describes how popular the package is relative to other packages.
[more]
|
92
|
Health:
Code health derived from static analysis.
[more]
|
100
|
Maintenance:
Reflects how tidy and up-to-date the package is.
[more]
|
90
|
Overall:
Weighted score of the above.
[more]
|
94
|
We analyzed this package on Feb 14, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:
Detected platforms: Flutter, web, other
No platform restriction found in libraries.
The description is too long. (-10 points)
Search engines display only the first part of the description. Try to keep the value of the description
field in your package's pubspec.yaml
file between 60 and 180 characters.
Package | Constraint | Resolved | Available |
---|---|---|---|
Direct dependencies | |||
Dart SDK | >=2.1.0 <3.0.0 | ||
analyzer | ^0.35.0 | 0.35.1 | |
args | >=1.4.0 <2.0.0 | 1.5.1 | |
glob | ^1.0.3 | 1.1.7 | |
meta | ^1.0.2 | 1.1.7 | |
source_span | ^1.0.2 | 1.5.4 | |
yaml | ^2.1.2 | 2.1.15 | |
Transitive dependencies | |||
async | 2.0.8 | ||
charcode | 1.1.2 | ||
collection | 1.14.11 | ||
convert | 2.1.1 | ||
crypto | 2.0.6 | ||
csslib | 0.14.6 | ||
front_end | 0.1.11 | ||
html | 0.13.3+3 | ||
kernel | 0.3.11 | ||
logging | 0.11.3+2 | ||
package_config | 1.0.5 | ||
plugin | 0.2.0+3 | ||
string_scanner | 1.0.4 | ||
term_glyph | 1.1.0 | ||
typed_data | 1.1.6 | ||
utf | 0.9.0+5 | ||
watcher | 0.9.7+10 | ||
Dev dependencies | |||
cli_util | ^0.1.2 | ||
dart_style | ^1.1.0 | ||
github | ^4.0.1 | ||
grinder | ^0.8.0 | ||
markdown | ^2.0.0 | ||
matcher | ^0.12.0 | ||
path | ^1.2.0 | 1.6.2 | |
pub_semver | ^1.4.2 | 1.4.2 | |
test | ^1.0.0 |