Linter for Dart

Lint Rules

Using the 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. Lints that are marked as deprecated should not be used and are subject to removal in future Linter releases.

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.

Many lints are included in various predefined rulesets:

Rules included in these rulesets are badged in the documentation below.

These rules are under active development. Feedback is welcome!

Error Rules

always_use_package_imports

Avoid relative imports for files in lib/.

avoid_empty_else
flutterpedantic

Avoid empty else statements.

avoid_print

Avoid print calls in production code.

avoid_relative_lib_imports
pedanticeffective dart

Avoid relative imports for files in lib/.

avoid_returning_null_for_future

Avoid returning null for Future.

avoid_slow_async_io

Avoid slow async dart:io methods.

avoid_types_as_parameter_names
pedantic

Avoid types as parameter names.

avoid_web_libraries_in_flutter (experimental)
flutter

Avoid using web-only libraries outside Flutter web plugin packages.

cancel_subscriptions
flutter

Cancel instances of dart.async.StreamSubscription.

close_sinks
flutter

Close instances of dart.core.Sink.

comment_references

Only reference in scope identifiers in doc comments.

control_flow_in_finally
flutter

Avoid control flow in finally blocks.

diagnostic_describe_all_properties

DO reference all public properties in debug methods.

empty_statements
flutter

Avoid empty statements.

hash_and_equals
fluttereffective dart

Always override hashCode if overriding ==.

invariant_booleans (experimental)

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

Boolean expression composed only with literals.

no_adjacent_strings_in_list

Don't use adjacent strings in list.

no_duplicate_case_values
pedantic

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

no_logic_in_create_state

Don't put any logic in createState.

prefer_relative_imports
effective dart

Prefer relative imports for files in lib/.

prefer_void_to_null

Don't use the Null type, unless you are positive that you don't want void.

test_types_in_equals
flutter

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

throw_in_finally
flutter

Avoid throw in finally block.

unnecessary_statements
flutter

Avoid using unnecessary statements.

unrelated_type_equality_checks
flutterpedantic

Equality operator == invocation with references of unrelated types.

unsafe_html

Avoid unsafe HTML APIs.

use_key_in_widget_constructors

Use key in widget constructors.

valid_regexps
flutterpedantic

Use valid regular expression syntax.

Style Rules

always_declare_return_types
pedantic

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
pedantic

Specify @required on named parameters without defaults.

always_specify_types

Specify type annotations.

annotate_overrides
pedantic

Annotate overridden members.

avoid_annotating_with_dynamic

Avoid annotating with dynamic when not required.

avoid_as

Avoid using as.

avoid_bool_literals_in_conditional_expressions

Avoid bool literals in conditional expressions.

avoid_catches_without_on_clauses
effective dart

Avoid catches without on clauses.

avoid_catching_errors
effective dart

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

avoid_classes_with_only_static_members
effective dart

Avoid defining a class that contains only static members.

avoid_double_and_int_checks

Avoid double and int checks.

avoid_equals_and_hash_code_on_mutable_classes
effective dart

AVOID overloading operator == and hashCode on classes not marked @immutable.

avoid_escaping_inner_quotes

Avoid escaping inner quotes by converting surrounding quotes.

avoid_field_initializers_in_const_classes

Avoid field initializers in const classes.

avoid_function_literals_in_foreach_calls
effective dart

Avoid using forEach with a function literal.

avoid_implementing_value_types

Don't implement classes that override ==.

avoid_init_to_null
flutterpedanticeffective dart

Don't explicitly initialize variables to null.

avoid_js_rounded_ints

Avoid JavaScript rounded ints.

avoid_null_checks_in_equality_operators
pedanticeffective dart

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

avoid_positional_boolean_parameters
effective dart

Avoid positional boolean parameters.

avoid_private_typedef_functions
effective dart

Avoid private typedef functions.

avoid_redundant_argument_values

Avoid redundant argument values.

avoid_renaming_method_parameters

Don't rename parameters of overridden methods.

avoid_return_types_on_setters
flutterpedanticeffective dart

Avoid return types on setters.

avoid_returning_null
effective dart

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

avoid_returning_null_for_void

Avoid returning null for void.

avoid_returning_this
effective dart

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

avoid_setters_without_getters
effective dart

Avoid setters without getters.

avoid_shadowing_type_parameters
pedantic

Avoid shadowing type parameters.

avoid_single_cascade_in_expression_statements

Avoid single cascade in expression statements.

avoid_types_on_closure_parameters
effective dart

Avoid annotating types for function expression parameters.

avoid_unnecessary_containers

Avoid unnecessary containers.

avoid_unused_constructor_parameters

Avoid defining unused parameters in constructors.

avoid_void_async

Avoid async functions that return void.

await_only_futures
flutter

Await only futures.

camel_case_extensions
pedanticeffective dart

Name extensions using UpperCamelCase.

camel_case_types
fluttereffective dart

Name types using UpperCamelCase.

cascade_invocations

Cascade consecutive method invocations on the same reference.

constant_identifier_names
effective dart

Prefer using lowerCamelCase for constant names.

curly_braces_in_flow_control_structures
pedanticeffective dart

DO use curly braces for all flow control structures.

directives_ordering
effective dart

Adhere to Effective Dart Guide directives sorting conventions.

do_not_use_environment

Do not use environment declared variables.

empty_catches
pedantic

Avoid empty catch blocks.

empty_constructor_bodies
flutterpedanticeffective dart

Use ; instead of {} for empty constructor bodies.

exhaustive_cases

Define case clauses for all constants in enum-like classes.

file_names
effective dart

Name source files using lowercase_with_underscores.

flutter_style_todos

Use Flutter TODO format: // TODO(username): message, https://URL-to-issue.

implementation_imports
fluttereffective dart

Don't import implementation files from another package.

join_return_with_assignment

Join return statement with assignment when possible.

leading_newlines_in_multiline_strings

Start multiline strings with a newline.

library_names
flutterpedanticeffective dart

Name libraries using lowercase_with_underscores.

library_prefixes
pedanticeffective dart

Use lowercase_with_underscores when specifying a library prefix.

lines_longer_than_80_chars
effective dart

AVOID lines longer than 80 characters.

missing_whitespace_between_adjacent_strings

Missing whitespace between adjacent strings.

no_default_cases (experimental)

No default cases.

no_runtimeType_toString

Avoid calling toString() on runtimeType.

non_constant_identifier_names
fluttereffective dart

Name non-constant identifiers using lowerCamelCase.

null_closures
pedantic

Do not pass null as an argument where a closure is expected.

omit_local_variable_types
pedanticeffective dart

Omit type annotations for local variables.

one_member_abstracts
effective dart

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
fluttereffective dart

Provide doc comments for all public APIs.

package_prefixed_library_names
flutter

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
pedanticeffective dart

Use adjacent strings to concatenate string literals.

prefer_asserts_in_initializer_lists

Prefer putting asserts in initializer list.

prefer_asserts_with_message

Prefer asserts with message.

prefer_bool_in_asserts (deprecated)

Prefer using a boolean as the assert condition.

prefer_collection_literals
pedanticeffective dart

Use collection literals when possible.

prefer_conditional_assignment
pedantic

Prefer using ??= over testing for null.

prefer_const_constructors

Prefer const with constant constructors.

prefer_const_constructors_in_immutables

Prefer declaring const constructors on @immutable classes.

prefer_const_declarations

Prefer const over final for declarations.

prefer_const_literals_to_create_immutables

Prefer const literals as parameters of constructors on @immutable classes.

prefer_constructors_over_static_methods

Prefer defining constructors instead of static methods to create instances.

prefer_contains
pedantic

Use contains for List and String instances.

prefer_double_quotes

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

prefer_equal_for_default_values
pedanticeffective dart

Use = to separate a named parameter from its default value.

prefer_expression_function_bodies

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

prefer_final_fields
pedanticeffective dart

Private field could be final.

prefer_final_in_for_each

Prefer final in for-each loop variable if reference is not reassigned.

prefer_final_locals

Prefer final for variable declarations if they are not reassigned.

prefer_for_elements_to_map_fromIterable
pedantic

Prefer for elements when building maps from iterables.

prefer_foreach

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

prefer_function_declarations_over_variables
effective dart

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

prefer_generic_function_type_aliases
pedanticeffective dart

Prefer generic function type aliases.

prefer_if_elements_to_conditional_expressions

Prefer if elements to conditional expressions where possible.

prefer_if_null_operators
pedantic

Prefer using if null operators.

prefer_initializing_formals
effective dart

Use initializing formals when possible.

prefer_inlined_adds

Inline list item declarations where possible.

prefer_int_literals

Prefer int literals over double literals.

prefer_interpolation_to_compose_strings
effective dart

Use interpolation to compose strings and values.

prefer_is_empty
pedantic

Use isEmpty for Iterables and Maps.

prefer_is_not_empty
flutterpedantic

Use isNotEmpty for Iterables and Maps.

prefer_is_not_operator

Prefer is! operator.

prefer_iterable_whereType
pedanticeffective dart

Prefer to use whereType on iterable.

prefer_mixin
effective dart

Prefer using mixins.

prefer_null_aware_operators

Prefer using null aware operators.

prefer_single_quotes
pedantic

Only use double quotes for strings containing single quotes.

prefer_spread_collections
pedantic

Use spread collections when possible.

prefer_typing_uninitialized_variables

Prefer typing uninitialized variables and fields.

provide_deprecation_message

Provide a deprecation message, via @Deprecated("message").

public_member_api_docs
effective dart

Document all public members.

recursive_getters
pedantic

Property getter recursively returns itself.

sized_box_for_whitespace

SizedBox for whitespace.

slash_for_doc_comments
flutterpedanticeffective dart

Prefer using /// for doc comments.

sort_child_properties_last

Sort child properties last in widget instance creations.

sort_constructors_first

Sort constructor declarations before other members.

sort_unnamed_constructors_first

Sort unnamed constructor declarations first.

super_goes_last (deprecated)

Place the super call last in a constructor initialization list.

type_annotate_public_apis
effective dart

Type annotate public APIs.

type_init_formals
flutterpedanticeffective dart

Don't type annotate initializing formals.

unawaited_futures
pedantic

Future results in async function bodies must be awaited or marked unawaited using package:pedantic.

unnecessary_await_in_return

Unnecessary await keyword in return.

unnecessary_brace_in_string_interps
fluttereffective dart

Avoid using braces in interpolation when not needed.

unnecessary_const
pedanticeffective dart

Avoid const keyword.

unnecessary_final

Don't use final for local variables.

unnecessary_getters_setters
fluttereffective dart

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

unnecessary_lambdas
effective dart

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

unnecessary_new
pedanticeffective dart

Unnecessary new keyword.

unnecessary_null_aware_assignments

Avoid null in null-aware assignment.

unnecessary_null_in_if_null_operators
pedantic

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_parenthesis

Unnecessary parenthesis can be removed.

unnecessary_raw_strings

Unnecessary raw string.

unnecessary_string_escapes

Remove unnecessary backslashes in strings.

unnecessary_string_interpolations

Unnecessary string interpolation.

unnecessary_this
pedanticeffective dart

Don't access members with this unless avoiding shadowing.

use_full_hex_values_for_flutter_colors

Prefer an 8-digit hexadecimal integer(0xFFFFFFFF) to instantiate Color.

use_function_type_syntax_for_parameters
pedantic

Use generic function type syntax for parameters.

use_is_even_rather_than_modulo

Prefer intValue.isOdd/isEven instead of checking the result of % 2.

use_raw_strings

Use raw string to avoid escapes.

use_rethrow_when_possible
pedanticeffective dart

Use rethrow to rethrow a caught exception.

use_setters_to_change_properties
effective dart

Use a setter for operations that conceptually change a property.

use_string_buffers

Use string buffers to compose strings.

use_to_and_as_if_applicable
effective dart

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

void_checks

Don't assign to void.

Pub Rules

package_names
flutter

Use lowercase_with_underscores for package names.

sort_pub_dependencies

Sort pub dependencies.