Lint Rules
This list is auto-generated from our sources.
Rules are organized into familiar rule groups.
Possible coding errors.
Matters of style, largely derived from the official Dart Style Guide.
Pub-related rules.
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:
flutter create
enables these by default).Rules included in these rulesets are badged in the documentation below.
These rules are under active development. Feedback is welcome!
Avoid relative imports for files in lib/
.
Avoid method calls or property accesses on a "dynamic" target.
avoid_empty_elseAvoid empty else statements.
avoid_printAvoid print
calls in production code.
Avoid relative imports for files in lib/
.
Avoid returning null for Future.
avoid_slow_async_ioAvoid slow async dart:io
methods.
Avoid
Avoid types as parameter names.
avoid_web_libraries_in_flutterAvoid using web-only libraries outside Flutter web plugin packages.
cancel_subscriptionsCancel instances of dart.async.StreamSubscription.
close_sinksClose instances of dart.core.Sink
.
Invocation of various collection methods with arguments of unrelated types.
comment_referencesOnly reference in scope identifiers in doc comments.
control_flow_in_finallyAvoid control flow in finally blocks.
deprecated_member_use_from_same_packageAvoid using deprecated elements from within the package in which they are declared.
diagnostic_describe_all_propertiesDO reference all public properties in debug methods.
discarded_futuresDon't invoke asynchronous functions in non-async blocks.
empty_statementsAvoid empty statements.
hash_and_equalsAlways override hashCode
if overriding ==
.
Don't implicitly reopen classes.
invalid_case_patterns (experimental)Use case expressions that are valid in Dart 3.0.
Conditions should not unconditionally evaluate to true
or to false
.
Invocation of Iterable
Invocation of remove
with references of unrelated types.
Boolean expression composed only with literals.
no_adjacent_strings_in_listDon't use adjacent strings in list.
no_duplicate_case_valuesDon't use more than one case with same value.
no_logic_in_create_stateDon't put any logic in createState.
prefer_relative_importsPrefer relative imports for files in lib/
.
Don't use the Null type, unless you are positive that you don't want void.
test_types_in_equalsTest type arguments in operator ==(Object other).
throw_in_finallyAvoid throw
in finally block.
Avoid using unnecessary statements.
unrelated_type_equality_checksEquality operator ==
invocation with references of unrelated types.
Avoid unsafe HTML APIs.
use_build_context_synchronously (experimental)Do not use BuildContexts across async gaps.
use_key_in_widget_constructorsUse key in widget constructors.
valid_regexpsUse valid regular expression syntax.
Declare method return types.
always_put_control_body_on_new_lineSeparate the control structure expression from its statement.
always_put_required_named_parameters_firstPut required named parameters first.
always_require_non_null_named_parameters (deprecated)Specify @required
on named parameters without defaults.
Specify type annotations.
annotate_overridesAnnotate overridden members.
avoid_annotating_with_dynamicAvoid annotating with dynamic when not required.
Avoid using as
.
Avoid bool literals in conditional expressions.
avoid_catches_without_on_clausesAvoid catches without on clauses.
avoid_catching_errorsDon't explicitly catch Error or types that implement it.
avoid_classes_with_only_static_membersAvoid defining a class that contains only static members.
avoid_double_and_int_checksAvoid double and int checks.
avoid_equals_and_hash_code_on_mutable_classesAvoid overloading operator == and hashCode on classes not marked @immutable
.
Avoid escaping inner quotes by converting surrounding quotes.
avoid_field_initializers_in_const_classesAvoid field initializers in const classes.
avoid_final_parametersAvoid final for parameter declarations.
avoid_function_literals_in_foreach_callsAvoid using forEach
with a function literal.
Don't implement classes that override ==
.
Don't explicitly initialize variables to null.
avoid_js_rounded_intsAvoid JavaScript rounded ints.
avoid_multiple_declarations_per_lineDon't declare multiple variables on a single line.
avoid_null_checks_in_equality_operatorsDon't check for null in custom == operators.
avoid_positional_boolean_parametersAvoid positional boolean parameters.
avoid_private_typedef_functionsAvoid private typedef functions.
avoid_redundant_argument_valuesAvoid redundant argument values.
avoid_renaming_method_parametersDon't rename parameters of overridden methods.
avoid_return_types_on_settersAvoid return types on setters.
avoid_returning_null (deprecated)Avoid returning null from members whose return type is bool, double, int, or num.
avoid_returning_null_for_voidAvoid returning null for void.
avoid_returning_thisAvoid returning this from methods just to enable a fluent interface.
avoid_setters_without_gettersAvoid setters without getters.
avoid_shadowing_type_parametersAvoid shadowing type parameters.
avoid_single_cascade_in_expression_statementsAvoid single cascade in expression statements.
avoid_types_on_closure_parametersAvoid annotating types for function expression parameters.
avoid_unnecessary_containersAvoid unnecessary containers.
avoid_unused_constructor_parametersAvoid defining unused parameters in constructors.
avoid_void_asyncAvoid async functions that return void.
await_only_futuresAwait only futures.
camel_case_extensionsName extensions using UpperCamelCase.
camel_case_typesName types using UpperCamelCase.
cascade_invocationsCascade consecutive method invocations on the same reference.
cast_nullable_to_non_nullableDon't cast a nullable value to a non nullable type.
combinators_orderingSort combinator names alphabetically.
conditional_uri_does_not_existMissing conditional import.
constant_identifier_namesPrefer using lowerCamelCase for constant names.
curly_braces_in_flow_control_structuresDO use curly braces for all flow control structures.
dangling_library_doc_commentsAttach library doc comments to library directives.
deprecated_consistencyMissing deprecated annotation.
directives_orderingAdhere to Effective Dart Guide directives sorting conventions.
do_not_use_environmentDo not use environment declared variables.
empty_catchesAvoid empty catch blocks.
empty_constructor_bodiesUse ;
instead of {}
for empty constructor bodies.
Do use sound null safety.
eol_at_end_of_filePut a single newline at end of file.
exhaustive_casesDefine case clauses for all constants in enum-like classes.
file_namesName source files using lowercase_with_underscores
.
Use Flutter TODO format: // TODO(username): message, https://URL-to-issue.
implementation_importsDon't import implementation files from another package.
implicit_call_tearoffsExplicitly tear-off call
methods when using an object as a Function.
Join return statement with assignment when possible.
leading_newlines_in_multiline_stringsStart multiline strings with a newline.
library_annotationsAttach library annotations to library directives.
library_namesName libraries using lowercase_with_underscores
.
Use lowercase_with_underscores
when specifying a library prefix.
Avoid using private types in public APIs.
lines_longer_than_80_charsAvoid lines longer than 80 characters.
missing_whitespace_between_adjacent_stringsMissing whitespace between adjacent strings.
no_default_cases (experimental)No default cases.
no_leading_underscores_for_library_prefixesAvoid leading underscores for library prefixes.
no_leading_underscores_for_local_identifiersAvoid leading underscores for local identifiers.
no_runtimeType_toStringAvoid calling toString() on runtimeType.
non_constant_identifier_namesName non-constant identifiers using lowerCamelCase.
noop_primitive_operationsNoop primitive operations.
null_check_on_nullable_type_parameterDon't use null check on a potentially nullable type parameter.
null_closuresDo not pass null
as an argument where a closure is expected.
Omit type annotations for local variables.
one_member_abstractsAvoid defining a one-member abstract class when a simple function will do.
only_throw_errorsOnly throw instances of classes extending either Exception or Error.
overridden_fieldsDon't override fields.
package_api_docsProvide doc comments for all public APIs.
package_prefixed_library_namesPrefix library names with the package name and a dot-separated path.
parameter_assignmentsDon't reassign references to parameters of functions or methods.
prefer_adjacent_string_concatenationUse adjacent strings to concatenate string literals.
prefer_asserts_in_initializer_listsPrefer putting asserts in initializer lists.
prefer_asserts_with_messagePrefer asserts with message.
Prefer using a boolean as the assert condition.
prefer_collection_literalsUse collection literals when possible.
prefer_conditional_assignmentPrefer using ??=
over testing for null.
Prefer const with constant constructors.
prefer_const_constructors_in_immutablesPrefer declaring const constructors on @immutable
classes.
Prefer const over final for declarations.
prefer_const_literals_to_create_immutablesPrefer const literals as parameters of constructors on @immutable classes.
prefer_constructors_over_static_methodsPrefer defining constructors instead of static methods to create instances.
prefer_containsUse contains for List
and String
instances.
Prefer double quotes where they won't require escape sequences.
Use =
to separate a named parameter from its default value.
Use => for short members whose body is a single return statement.
prefer_final_fieldsPrivate field could be final.
prefer_final_in_for_eachPrefer final in for-each loop variable if reference is not reassigned.
prefer_final_localsPrefer final for variable declarations if they are not reassigned.
prefer_final_parametersPrefer final for parameter declarations if they are not reassigned.
prefer_for_elements_to_map_fromIterablePrefer 'for' elements when building maps from iterables.
prefer_foreachUse forEach
to only apply a function to all the elements.
Use a function declaration to bind a function to a name.
prefer_generic_function_type_aliasesPrefer generic function type aliases.
prefer_if_elements_to_conditional_expressionsPrefer if elements to conditional expressions where possible.
prefer_if_null_operatorsPrefer using if null operators.
prefer_initializing_formalsUse initializing formals when possible.
prefer_inlined_addsInline list item declarations where possible.
prefer_int_literalsPrefer int literals over double literals.
prefer_interpolation_to_compose_stringsUse interpolation to compose strings and values.
prefer_is_emptyUse isEmpty
for Iterables and Maps.
Use isNotEmpty
for Iterables and Maps.
Prefer is! operator.
prefer_iterable_whereTypePrefer to use whereType on iterable.
prefer_mixinPrefer using mixins.
prefer_null_aware_method_callsPrefer null aware method calls.
prefer_null_aware_operatorsPrefer using null aware operators.
prefer_single_quotesOnly use double quotes for strings containing single quotes.
prefer_spread_collectionsUse spread collections when possible.
prefer_typing_uninitialized_variablesPrefer typing uninitialized variables and fields.
provide_deprecation_messageProvide a deprecation message, via @Deprecated("message").
public_member_api_docsDocument all public members.
recursive_gettersProperty getter recursively returns itself.
require_trailing_commasUse trailing commas for all function calls and declarations.
sized_box_for_whitespaceSizedBox for whitespace.
sized_box_shrink_expandUse SizedBox shrink and expand named constructors.
slash_for_doc_commentsPrefer using /// for doc comments.
sort_child_properties_lastSort child properties last in widget instance creations.
sort_constructors_firstSort constructor declarations before other members.
sort_unnamed_constructors_firstSort unnamed constructor declarations first.
Place the super
call last in a constructor initialization list.
Tighten type of initializing formal.
type_annotate_public_apisType annotate public APIs.
type_init_formalsDon't type annotate initializing formals.
type_literal_in_constant_patternDon't use constant patterns with type literals.
unawaited_futuresFuture
results in async
function bodies must be await
ed or marked unawaited
using dart:async
.
Unnecessary await keyword in return.
unnecessary_brace_in_string_interpsAvoid using braces in interpolation when not needed.
unnecessary_breaksDon't use explicit break
s when a break is implied.
Avoid const keyword.
unnecessary_constructor_nameUnnecessary .new
constructor name.
Don't use final
for local variables.
Avoid wrapping fields in getters and setters just to be "safe".
unnecessary_lambdasDon't create a lambda when a tear-off will do.
unnecessary_lateDon't specify the late
modifier when it is not needed.
Avoid library directives unless they have documentation comments or annotations.
unnecessary_newUnnecessary new keyword.
unnecessary_null_aware_assignmentsAvoid null in null-aware assignment.
unnecessary_null_aware_operator_on_extension_on_nullableUnnecessary null aware operator on extension on a nullable type.
unnecessary_null_checks (experimental)Unnecessary null checks.
unnecessary_null_in_if_null_operatorsAvoid using null
in if null
operators.
Use a non-nullable type for a final variable initialized with a non-nullable value.
unnecessary_overridesDon't override a method to do a super method invocation with the same parameters.
unnecessary_parenthesisUnnecessary parentheses can be removed.
unnecessary_raw_stringsUnnecessary raw string.
unnecessary_string_escapesRemove unnecessary backslashes in strings.
unnecessary_string_interpolationsUnnecessary string interpolation.
unnecessary_thisDon't access members with this
unless avoiding shadowing.
Unnecessary toList() in spreads.
unreachable_from_main (experimental)Unreachable top-level members in executable libraries.
use_colored_boxUse ColoredBox
.
Use DecoratedBox
.
Use enums rather than classes that behave like enums.
use_full_hex_values_for_flutter_colorsPrefer an 8-digit hexadecimal integer(0xFFFFFFFF) to instantiate Color.
use_function_type_syntax_for_parametersUse generic function type syntax for parameters.
use_if_null_to_convert_nulls_to_boolsUse if-null operators to convert nulls to bools.
use_is_even_rather_than_moduloPrefer intValue.isOdd/isEven instead of checking the result of % 2.
use_late_for_private_fields_and_variables (experimental)Use late for private members with a non-nullable type.
use_named_constantsUse predefined named constants.
use_raw_stringsUse raw string to avoid escapes.
use_rethrow_when_possibleUse rethrow to rethrow a caught exception.
use_setters_to_change_propertiesUse a setter for operations that conceptually change a property.
use_string_buffersUse string buffers to compose strings.
use_string_in_part_of_directivesUse string in part of directives.
use_super_parameters (experimental)Use super-initializer parameters where possible.
use_test_throws_matchersUse throwsA matcher instead of fail().
use_to_and_as_if_applicableStart the name of the method with to/_to or as/_as if applicable.
void_checksDon't assign to void.
Depend on referenced packages.
package_namesUse lowercase_with_underscores
for package names.
Use secure urls in pubspec.yaml
.
Sort pub dependencies alphabetically.