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 or through an analysis options file.

As some lints may contradict each other, only a subset of these 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.

avoid_slow_async_io

Avoid slow async dart:io methods.

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 blocks.

empty_statements

Avoid empty statements.

hash_and_equals

Always override hashCode if overriding ==.

invariant_booleans

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 remove with references of unrelated types.

literal_only_boolean_expressions (stable)

Boolean expression composed only with literals.

no_adjacent_strings_in_list

Don't use adjacent strings in list.

no_duplicate_case_values

Don't use more than one case with same value.

test_types_in_equals

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

throw_in_finally

Avoid throw in finally block.

unnecessary_statements

Avoid using unnecessary statements.

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_put_control_body_on_new_line

Separate the control structure expression from its statement.

always_put_required_named_parameters_first

Put @required named parameters first.

always_require_non_null_named_parameters

Use @required.

always_specify_types

Specify type annotations.

annotate_overrides

Annotate overridden members.

avoid_annotating_with_dynamic

Avoid annotating with dynamic when not required.

avoid_as

Avoid using as.

avoid_catches_without_on_clauses

Avoid catches without on clauses.

avoid_catching_errors

Don't explicitly catch Error or types that implement it.

avoid_classes_with_only_static_members

Avoid defining a class that contains only static members.

avoid_function_literals_in_foreach_calls

Avoid using forEach with a function literal.

avoid_init_to_null

Don't explicitly initialize variables to null.

avoid_null_checks_in_equality_operators

Don't check for null in custom == operators.

avoid_positional_boolean_parameters (stable)

Avoid positional boolean parameters.

avoid_return_types_on_setters

Avoid return types on setters.

avoid_returning_null

Avoid returning null from members whose return type is bool, double, int, or num.

avoid_returning_this

Avoid returning this from methods just to enable a fluent interface.

avoid_setters_without_getters

Avoid setters without getters.

avoid_types_on_closure_parameters

Avoid annotating types for function expression parameters.

avoid_unused_constructor_parameters

Avoid defining unused paramters in constructors.

await_only_futures

Await only futures.

camel_case_types

Name types using UpperCamelCase.

cascade_invocations

Cascade consecutive method invocations on the same reference.

constant_identifier_names

Prefer using lowerCamelCase for constant names.

directives_ordering

Adhere to Effective Dart Guide directives sorting conventions.

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.

join_return_with_assignment

Join return statement with assignment when possible.

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.

omit_local_variable_types

Omit type annotations for local variables.

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

Don't 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_adjacent_string_concatenation

Use adjacent strings to concatenate string literals.

prefer_asserts_in_initializer_lists

Prefer putting asserts in initializer list.

prefer_bool_in_asserts

Prefer using a boolean as the assert condition.

prefer_collection_literals

Use collection literals when possible.

prefer_conditional_assignment

Prefer using ??= over testing for null.

prefer_const_constructors

Prefer const with constant constructors.

prefer_const_constructors_in_immutables

Prefer declare const constructors on @immutable classes.

prefer_constructors_over_static_methods

Prefer defining constructors instead of static methods to create instances.

prefer_contains

Use contains for List and String instances.

prefer_expression_function_bodies

Use => for short members whose body is a single return statement.

prefer_final_fields

Private field could be final.

prefer_final_locals

Prefer final for variable declaration if reference is not reassigned.

prefer_foreach (stable)

Use forEach to only apply a function to all the elements.

prefer_function_declarations_over_variables

Use a function declaration to bind a function to a name.

prefer_initializing_formals

Use initializing formals when possible.

prefer_interpolation_to_compose_strings

Use interpolation to compose strings and values.

prefer_is_empty

Use isEmpty for Iterables and Maps.

prefer_is_not_empty

Use isNotEmpty for Iterables and Maps.

prefer_single_quotes

Prefer single quotes where they won't require escape sequences.

prefer_typing_uninitialized_variables

Prefer typing uninitialized variables and fields.

public_member_api_docs

Document all public members.

recursive_getters

Property getter recursively returns itself.

slash_for_doc_comments

Prefer using /// 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 future-returning functions inside async function bodies.

unnecessary_brace_in_string_interps

Avoid using braces in interpolation when not needed.

unnecessary_getters_setters

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

unnecessary_lambdas

Don't create a lambda when a tear-off will do.

unnecessary_null_aware_assignments

Avoid null in null-aware assignment.

unnecessary_null_in_if_null_operators

Avoid using null in if null operators.

unnecessary_overrides

Don't override a method to do a super method invocation with the same parameters.

unnecessary_this

Don't access members with this unless avoiding shadowing.

use_rethrow_when_possible

Use rethrow to rethrow a caught exception.

use_setters_to_change_properties

Use a setter for operations that conceptually change a property.

use_string_buffers

Use string buffer to compose strings.

use_to_and_as_if_applicable

Start the name of the method with to/_to or as/_as if applicable.

Pub Rules

package_names

Use lowercase_with_underscores for package names.