Dart Lint

Lint Rules

View the Project on GitHub dartlang/linter

Supported Lint Rules

This list is auto-generated from our sources.

Rules are organized into familiar rule groups.

In addition, rules can be further distinguished by maturity. Unqualified rules are considered stable, while others may be marked experimental to indicate that they are under review.

Rules can be selectively enabled in the analyzer using analysis options. An auto-generated list enabling all options is provided here. As some lints may contradict each other, only some lints will be enabled in practice, but this list should provide a convenient jumping-off point.

These rules are under active development. Feedback is welcome!

Error Rules

avoid_empty_else

Avoid empty else statements.

cancel_subscriptions

Cancel instances of dart.async.StreamSubscription.

close_sinks

Close instances of dart.core.Sink.

comment_references

Only reference in scope identifiers in doc comments.

control_flow_in_finally

Avoid control flow in finally block.

empty_statements

Avoid empty statements.

hash_and_equals

Always override hashCode if overriding ==

invariant_booleans (stable)

Conditions should not unconditionally evaluate to "TRUE" or to "FALSE"

iterable_contains_unrelated_type

Invocation of Iterable.contains with references of unrelated types.

list_remove_unrelated_type

Invocation of List.remove with references of unrelated types.

literal_only_boolean_expressions (stable)

Conditions should not unconditionally evaluate to "TRUE" or to "FALSE"

test_types_in_equals

Test type arguments in operator ==(Object other).

throw_in_finally

Avoid throw in finally block.

unrelated_type_equality_checks

Equality operator (==) invocation with references of unrelated types.

valid_regexps

Use valid regular expression syntax.

Style Rules

always_declare_return_types

Declare method return types.

always_specify_types

Specify type annotations.

annotate_overrides

Annotate overridden members

avoid_as

Avoid using as.

avoid_init_to_null

Don't explicitly initialize variables to null

avoid_return_types_on_setters

Avoid return types on setters.

await_only_futures

Await only futures.

camel_case_types

Name types using UpperCamelCase.

constant_identifier_names

Prefer using lowerCamelCase for constant names.

empty_catches

Avoid empty catch blocks.

empty_constructor_bodies

Use ; instead of {} for empty constructor bodies.

implementation_imports

Don't import implementation files from another package.

library_names

Name libraries and source files using lowercase_with_underscores.

library_prefixes

Use lowercase_with_underscores when specifying a library prefix.

non_constant_identifier_names

Name non-constant identifiers using lowerCamelCase.

one_member_abstracts

Avoid defining a one-member abstract class when a simple function will do.

only_throw_errors

Only throw instances of classes extending either Exception or Error

overridden_fields

Do not override fields.

package_api_docs

Provide doc comments for all public APIs

package_prefixed_library_names

Prefix library names with the package name and a dot-separated path.

parameter_assignments

Don't reassign references to parameters of functions or methods.

prefer_final_fields

Private field could be final.

prefer_final_locals

Prefer final for variable declaration if reference is not reassigned.

prefer_is_not_empty

Use isNotEmpty for Iterables and Maps.

public_member_api_docs

Document all public members

slash_for_doc_comments

Prefer to use /// for doc comments

sort_constructors_first

Sort constructor declarations before method declarations.

sort_unnamed_constructors_first

Sort unnamed constructor declarations first

super_goes_last

Place the super() call last in a constructor initialization list.

type_annotate_public_apis

Type annotate public APIs.

type_init_formals

Don't type annotate initializing formals.

unawaited_futures

Await for future expression statements inside async function bodies.

unnecessary_brace_in_string_interp

Avoid using braces in interpolation when not needed.

unnecessary_getters_setters

Avoid wrapping fields in getters and setters just to be "safe".

Pub Rules

package_names

Use lowercase_with_underscores for package names.