Skip to main content

Linter rules

Details about the Dart linter and its style rules you can choose.

Use the Dart linter to identify possible problems in your Dart code. You can use the linter through your IDE or with the dart analyze command. For information on how to enable and disable individual linter rules, see individual rules sections of the analyzer documentation.

This page lists all the linter rules, with details such as when you might want to use each rule, what code patterns trigger it, and how you might fix your code.

Sets

#

To avoid the need to individually select compatible linter rules, consider starting with a linter rule set, which the following packages provide:

lints

Contains two rule sets curated by the Dart team. We recommend using at least the core rule set, which is used when scoring packages uploaded to pub.dev. Or, better yet, use the recommended rule set, a superset of core that identifies additional issues and enforces style and format. If you're writing Flutter code, use the rule set in the flutter_lints package, which builds on lints.

flutter_lints

Contains the flutter rule set, which the Flutter team encourages you to use in Flutter apps, packages, and plugins. This rule set is a superset of the recommended set, which is itself a superset of the core set that partially determines the score of packages uploaded to pub.dev.

To learn how to use a specific rule set, visit the documentation for enabling and disabling linter rules.

To find more predefined rule sets, check out the #lints topic on pub.dev.

Status

#

Each rule has a status or maturity level:

Stable

These rules are safe to use and are verified as functional with the latest versions of the Dart language. All rules are considered stable unless they're marked as experimental, deprecated, or removed.

Experimental

These rules are still under evaluation and might never be stabilized. Use these with caution and report any issues you come across.

Deprecated

These rules are no longer suggested for use and might be removed in a future Dart release.

Removed

These rules have already been removed in the latest stable Dart release.

Quick fixes

#

Some rules can be fixed automatically using quick fixes. A quick fix is an automated edit targeted at fixing the issue reported by the linter rule.

If the rule has a quick fix, it can be applied using dart fix or using your editor with Dart support. To learn more, see Quick fixes for analysis issues.

Rules

#

The following is an index of all linter rules and a short description of their functionality. To learn more about a specific rule, click the Learn more button on its card.

For an auto-generated list containing all linter rules in Dart 3.10.3, check out All linter rules.


always_declare_return_types
Declare method return types.
build
Learn more
always_put_control_body_on_new_line
Separate the control structure expression from its statement.
build
Learn more
always_put_required_named_parameters_first
Put required named parameters first.
build
Learn more
always_require_non_null_named_parameters
Specify @required on named parameters without defaults.
error
Learn more
always_specify_types
Specify type annotations.
build
Learn more
always_use_package_imports
Avoid relative imports for files in lib/.
build
Learn more
annotate_overrides
Annotate overridden members.
build thumb_up flutter
Learn more
annotate_redeclares
Annotate redeclared members.
science build
Learn more
avoid_annotating_with_dynamic
Avoid annotating with dynamic when not required.
build
Learn more
avoid_as
Avoid using as.
error
Learn more
avoid_bool_literals_in_conditional_expressions
Avoid bool literals in conditional expressions.
build
Learn more
avoid_catches_without_on_clauses
Avoid catches without on clauses.
Learn more
avoid_catching_errors
Don't explicitly catch Error or types that implement it.
Learn more
avoid_classes_with_only_static_members
Avoid defining a class that contains only static members.
Learn more
avoid_double_and_int_checks
Avoid double and int checks.
Learn more
avoid_dynamic_calls
Avoid method calls or property accesses on a dynamic target.
Learn more
avoid_empty_else
Avoid empty statements in else clauses.
build circles thumb_up flutter
Learn more
avoid_equals_and_hash_code_on_mutable_classes
Avoid overloading operator == and hashCode on classes not marked @immutable.
Learn more
avoid_escaping_inner_quotes
Avoid escaping inner quotes by converting surrounding quotes.
build
Learn more
avoid_field_initializers_in_const_classes
Avoid field initializers in const classes.
Learn more
avoid_final_parameters
Avoid final for parameter declarations.
Learn more
avoid_function_literals_in_foreach_calls
Avoid using forEach with a function literal.
build thumb_up flutter
Learn more
avoid_futureor_void
Avoid using 'FutureOr' as the type of a result.
science
Learn more
avoid_implementing_value_types
Don't implement classes that override ==.
Learn more
avoid_init_to_null
Don't explicitly initialize variables to null.
build thumb_up flutter
Learn more
avoid_js_rounded_ints
Avoid JavaScript rounded ints.
Learn more
avoid_multiple_declarations_per_line
Don't declare multiple variables on a single line.
build
Learn more
avoid_null_checks_in_equality_operators
Don't check for null in custom == operators.
report build
Learn more
avoid_positional_boolean_parameters
Avoid positional boolean parameters.
Learn more
avoid_print
Avoid print calls in production code.
build flutter
Learn more
avoid_private_typedef_functions
Avoid private typedef functions.
build
Learn more
avoid_redundant_argument_values
Avoid redundant argument values.
build
Learn more
avoid_relative_lib_imports
Avoid relative imports for files in lib/.
build circles thumb_up flutter
Learn more
avoid_renaming_method_parameters
Don't rename parameters of overridden methods.
build thumb_up flutter
Learn more
avoid_return_types_on_setters
Avoid return types on setters.
build thumb_up flutter
Learn more
avoid_returning_null
Avoid returning null from members whose return type is bool, double, int, or num.
error
Learn more
avoid_returning_null_for_future
Avoid returning null for Future.
error
Learn more
avoid_returning_null_for_void
Avoid returning null for void.
build thumb_up flutter
Learn more
avoid_returning_this
Avoid returning this from methods just to enable a fluent interface.
Learn more
avoid_setters_without_getters
Avoid setters without getters.
Learn more
avoid_shadowing_type_parameters
Avoid shadowing type parameters.
circles thumb_up flutter
Learn more
avoid_single_cascade_in_expression_statements
Avoid single cascade in expression statements.
build thumb_up flutter
Learn more
avoid_slow_async_io
Avoid slow asynchronous dart:io methods.
Learn more
avoid_type_to_string
Avoid .toString() in production code since results may be minified.
Learn more
avoid_types_as_parameter_names
Avoid types as parameter names.
circles thumb_up flutter
Learn more
avoid_types_on_closure_parameters
Avoid annotating types for function expression parameters.
build
Learn more
avoid_unnecessary_containers
Avoid unnecessary containers.
build flutter
Learn more
avoid_unstable_final_fields
Avoid overriding a final field to return different values if called multiple times.
error
Learn more
avoid_unused_constructor_parameters
Avoid defining unused parameters in constructors.
build
Learn more
avoid_void_async
Avoid async functions that return void.
build
Learn more
avoid_web_libraries_in_flutter
Avoid using web-only libraries outside Flutter web plugin packages.
flutter
Learn more
await_only_futures
Await only futures.
build circles thumb_up flutter
Learn more
camel_case_extensions
Name extensions using UpperCamelCase.
circles thumb_up flutter
Learn more
camel_case_types
Name types using UpperCamelCase.
circles thumb_up flutter
Learn more
cancel_subscriptions
Cancel instances of dart:async StreamSubscription.
Learn more
cascade_invocations
Cascade consecutive method invocations on the same reference.
build
Learn more
cast_nullable_to_non_nullable
Don't cast a nullable value to a non nullable type.
build
Learn more
close_sinks
Close instances of dart:core Sink.
Learn more
collection_methods_unrelated_type
Invocation of various collection methods with arguments of unrelated types.
circles thumb_up flutter
Learn more
combinators_ordering
Sort combinator names alphabetically.
build
Learn more
comment_references
Only reference in-scope identifiers in doc comments.
build
Learn more
conditional_uri_does_not_exist
Missing conditional import.
Learn more
constant_identifier_names
Prefer using lowerCamelCase for constant names.
build thumb_up flutter
Learn more
control_flow_in_finally
Avoid control flow in finally blocks.
thumb_up flutter
Learn more
curly_braces_in_flow_control_structures
DO use curly braces for all flow control structures.
build circles thumb_up flutter
Learn more
dangling_library_doc_comments
Attach library doc comments to library directives.
build circles thumb_up flutter
Learn more
depend_on_referenced_packages
Depend on referenced packages.
circles thumb_up flutter
Learn more
deprecated_consistency
Missing deprecated annotation.
Learn more
deprecated_member_use_from_same_package
Avoid using deprecated elements from within the package in which they are declared.
build
Learn more
diagnostic_describe_all_properties
DO reference all public properties in debug methods.
build
Learn more
directives_ordering
Adhere to Effective Dart Guide directives sorting conventions.
build
Learn more
discarded_futures
There should be no Future -returning calls in synchronous functions unless they are assigned or returned.
build
Learn more
do_not_use_environment
Do not use environment declared variables.
Learn more
document_ignores
Document ignore comments.
Learn more
empty_catches
Avoid empty catch blocks.
build circles thumb_up flutter
Learn more
empty_constructor_bodies
Use ; instead of {} for empty constructor bodies.
build thumb_up flutter
Learn more
empty_statements
Avoid empty statements.
build thumb_up flutter
Learn more
enable_null_safety
Do use sound null safety.
error
Learn more
eol_at_end_of_file
Put a single newline at end of file.
build
Learn more
exhaustive_cases
Define case clauses for all constants in enum-like classes.
build thumb_up flutter
Learn more
file_names
Name source files using lowercase_with_underscores.
circles thumb_up flutter
Learn more
flutter_style_todos
Use Flutter TODO format: // TODO(username): message, https://URL-to-issue.
build
Learn more
hash_and_equals
Always override hashCode if overriding ==.
build circles thumb_up flutter
Learn more
implementation_imports
Don't import implementation files from another package.
thumb_up flutter
Learn more
implicit_call_tearoffs
Explicitly tear-off call methods when using an object as a Function.
build circles thumb_up flutter
Learn more
implicit_reopen
Don't implicitly reopen classes.
science build
Learn more
invalid_case_patterns
Use case expressions that are valid in Dart 3.0.
science build
Learn more
invalid_runtime_check_with_js_interop_types
Avoid runtime type tests with JS interop types where the result may not be platform-consistent.
thumb_up flutter
Learn more
invariant_booleans
Conditions should not unconditionally evaluate to true or to false.
error
Learn more
iterable_contains_unrelated_type
Invocation of Iterable<E>.contains with references of unrelated types.
error
Learn more
join_return_with_assignment
Join return statement with assignment when possible.
Learn more
leading_newlines_in_multiline_strings
Start multiline strings with a newline.
build
Learn more
library_annotations
Attach library annotations to library directives.
build circles thumb_up flutter
Learn more
library_names
Name libraries using lowercase_with_underscores.
Learn more
library_prefixes
Use lowercase_with_underscores when specifying a library prefix.
thumb_up flutter
Learn more
library_private_types_in_public_api
Avoid using private types in public APIs.
thumb_up flutter
Learn more
lines_longer_than_80_chars
Avoid lines longer than 80 characters.
Learn more
list_remove_unrelated_type
Invocation of remove with references of unrelated types.
error
Learn more
literal_only_boolean_expressions
Boolean expression composed only with literals.
Learn more
matching_super_parameters
Use matching super parameter names.
Learn more
missing_code_block_language_in_doc_comment
A code block is missing a specified language.
Learn more
missing_whitespace_between_adjacent_strings
Missing whitespace between adjacent strings.
Learn more
no_adjacent_strings_in_list
Don't use adjacent strings in list.
Learn more
no_default_cases
No default cases.
science
Learn more
no_duplicate_case_values
Don't use more than one case with same value.
build circles thumb_up flutter
Learn more
no_leading_underscores_for_library_prefixes
Avoid leading underscores for library prefixes.
build thumb_up flutter
Learn more
no_leading_underscores_for_local_identifiers
Avoid leading underscores for local identifiers.
build thumb_up flutter
Learn more
no_literal_bool_comparisons
Don't compare boolean expressions to boolean literals.
build
Learn more
no_logic_in_create_state
Don't put any logic in createState.
flutter
Learn more
no_runtimetype_tostring
Avoid calling toString() on runtimeType.
Learn more
no_self_assignments
Don't assign a variable to itself.
Learn more
no_wildcard_variable_uses
Don't use wildcard parameters or variables.
circles thumb_up flutter
Learn more
non_constant_identifier_names
Name non-constant identifiers using lowerCamelCase.
build circles thumb_up flutter
Learn more
noop_primitive_operations
Noop primitive operations.
build
Learn more
null_check_on_nullable_type_parameter
Don't use null check on a potentially nullable type parameter.
build circles thumb_up flutter
Learn more
null_closures
Do not pass null as an argument where a closure is expected.
build thumb_up flutter
Learn more
omit_local_variable_types
Omit type annotations for local variables.
build
Learn more
omit_obvious_local_variable_types
Omit obvious type annotations for local variables.
science build
Learn more
omit_obvious_property_types
Omit obvious type annotations for top-level and static variables.
science build
Learn more
one_member_abstracts
Avoid defining a one-member abstract class when a simple function will do.
Learn more
only_throw_errors
Only throw instances of classes extending either Exception or Error.
Learn more
overridden_fields
Don't override fields.
thumb_up flutter
Learn more
package_api_docs
Provide doc comments for all public APIs.
error
Learn more
package_names
Use lowercase_with_underscores for package names.
thumb_up flutter
Learn more
package_prefixed_library_names
Prefix library names with the package name and a dot-separated path.
Learn more
parameter_assignments
Don't reassign references to parameters of functions or methods.
Learn more
prefer_adjacent_string_concatenation
Use adjacent strings to concatenate string literals.
build thumb_up flutter
Learn more
prefer_asserts_in_initializer_lists
Prefer putting asserts in initializer lists.
Learn more
prefer_asserts_with_message
Prefer asserts with message.
Learn more
prefer_bool_in_asserts
Prefer using a boolean as the assert condition.
error
Learn more
prefer_collection_literals
Use collection literals when possible.
build thumb_up flutter
Learn more
prefer_conditional_assignment
Prefer using ??= over testing for null.
build thumb_up flutter
Learn more
prefer_const_constructors
Prefer const with constant constructors.
build
Learn more
prefer_const_constructors_in_immutables
Prefer declaring const constructors on @immutable classes.
build flutter
Learn more
prefer_const_declarations
Prefer const over final for declarations.
build
Learn more
prefer_const_literals_to_create_immutables
Prefer const literals as parameters of constructors on @immutable classes.
build
Learn more
prefer_constructors_over_static_methods
Prefer defining constructors instead of static methods to create instances.
Learn more
prefer_contains
Use contains for List and String instances.
build thumb_up flutter
Learn more
prefer_double_quotes
Prefer double quotes where they won't require escape sequences.
build
Learn more
prefer_equal_for_default_values
Use = to separate a named parameter from its default value.
error
Learn more
prefer_expression_function_bodies
Use => for short members whose body is a single return statement.
build
Learn more
prefer_final_fields
Private field could be final.
build thumb_up flutter
Learn more
prefer_final_in_for_each
Prefer final in for-each loop variable if reference is not reassigned.
build
Learn more
prefer_final_locals
Prefer final for variable declarations if they are not reassigned.
build
Learn more
prefer_final_parameters
Prefer final for parameter declarations if they are not reassigned.
report build
Learn more
prefer_for_elements_to_map_fromiterable
Prefer for elements when building maps from iterables.
build thumb_up flutter
Learn more
prefer_foreach
Use forEach to only apply a function to all the elements.
build
Learn more
prefer_function_declarations_over_variables
Use a function declaration to bind a function to a name.
build thumb_up flutter
Learn more
prefer_generic_function_type_aliases
Prefer generic function type aliases.
build circles thumb_up flutter
Learn more
prefer_if_elements_to_conditional_expressions
Prefer if elements to conditional expressions where possible.
build
Learn more
prefer_if_null_operators
Prefer using ?? operators.
build thumb_up flutter
Learn more
prefer_initializing_formals
Use initializing formals when possible.
build thumb_up flutter
Learn more
prefer_inlined_adds
Inline list item declarations where possible.
build thumb_up flutter
Learn more
prefer_int_literals
Prefer int literals over double literals.
build
Learn more
prefer_interpolation_to_compose_strings
Use interpolation to compose strings and values.
build thumb_up flutter
Learn more
prefer_is_empty
Use isEmpty for Iterables and Maps.
build circles thumb_up flutter
Learn more
prefer_is_not_empty
Use isNotEmpty for Iterables and Maps.
build circles thumb_up flutter
Learn more
prefer_is_not_operator
Prefer is! operator.
build thumb_up flutter
Learn more
prefer_iterable_wheretype
Prefer to use whereType on iterable.
build circles thumb_up flutter
Learn more
prefer_mixin
Prefer using mixins.
Learn more
prefer_null_aware_method_calls
Prefer null-aware method calls.
Learn more
prefer_null_aware_operators
Prefer using null-aware operators.
build thumb_up flutter
Learn more
prefer_relative_imports
Prefer relative imports for files in lib/.
build
Learn more
prefer_single_quotes
Only use double quotes for strings containing single quotes.
build
Learn more
prefer_spread_collections
Use spread collections when possible.
build thumb_up flutter
Learn more
prefer_typing_uninitialized_variables
Prefer typing uninitialized variables and fields.
build circles thumb_up flutter
Learn more
prefer_void_to_null
Don't use the Null type, unless you are positive that you don't want void.
build
Learn more
provide_deprecation_message
Provide a deprecation message, via @Deprecated("message").
circles thumb_up flutter
Learn more
public_member_api_docs
Document all public members.
Learn more
recursive_getters
Property getter recursively returns itself.
thumb_up flutter
Learn more
remove_deprecations_in_breaking_versions
Deprecation in major version.
Learn more
require_trailing_commas
Use trailing commas for all parameter lists and argument lists.
build
Learn more
secure_pubspec_urls
Use secure urls in pubspec.yaml.
circles thumb_up flutter
Learn more
simplify_variable_pattern
Avoid unnecessary member names in variable patterns.
build
Learn more
sized_box_for_whitespace
SizedBox for whitespace.
build flutter
Learn more
sized_box_shrink_expand
Use SizedBox shrink and expand named constructors.
Learn more
slash_for_doc_comments
Prefer using /// for doc comments.
build thumb_up flutter
Learn more
sort_child_properties_last
Sort child properties last in widget instance creations.
build flutter
Learn more
sort_constructors_first
Sort constructor declarations before other members.
build
Learn more
sort_pub_dependencies
Sort pub dependencies alphabetically.
Learn more
sort_unnamed_constructors_first
Sort unnamed constructor declarations first.
build
Learn more
specify_nonobvious_local_variable_types
Specify non-obvious type annotations for local variables.
science build
Learn more
specify_nonobvious_property_types
Specify non-obvious type annotations for top-level and static variables.
science build
Learn more
strict_top_level_inference
Specify type annotations.
build circles thumb_up flutter
Learn more
super_goes_last
Place the super call last in a constructor initialization list.
error
Learn more
switch_on_type
Avoid switch statements on a 'Type'.
Learn more
test_types_in_equals
Test type of argument in operator ==(Object other).
Learn more
throw_in_finally
Avoid throw in finally block.
Learn more
tighten_type_of_initializing_formals
Tighten type of initializing formal.
Learn more
type_annotate_public_apis
Type annotate public APIs.
build
Learn more
type_init_formals
Don't type annotate initializing formals.
build thumb_up flutter
Learn more
type_literal_in_constant_pattern
Don't use constant patterns with type literals.
build circles thumb_up flutter
Learn more
unawaited_futures
Future results in async function bodies must be await ed or marked unawaited using dart:async .
build
Learn more
unintended_html_in_doc_comment
Use of angle brackets in a doc comment is treated as HTML by Markdown.
circles thumb_up flutter
Learn more
unnecessary_async
No await no async.
science build
Learn more
unnecessary_await_in_return
Unnecessary await keyword in return.
build
Learn more
unnecessary_brace_in_string_interps
Avoid using braces in interpolation when not needed.
build thumb_up flutter
Learn more
unnecessary_breaks
Don't use explicit breaks when a break is implied.
build
Learn more
unnecessary_const
Avoid const keyword.
build thumb_up flutter
Learn more
unnecessary_constructor_name
Unnecessary .new constructor name.
build thumb_up flutter
Learn more
unnecessary_final
Don't use final for local variables.
build
Learn more
unnecessary_getters_setters
Avoid wrapping fields in getters and setters just to be "safe".
build thumb_up flutter
Learn more
unnecessary_ignore
Don't ignore a diagnostic code that is not produced.
build
Learn more
unnecessary_lambdas
Don't create a lambda when a tear-off will do.
build
Learn more
unnecessary_late
Don't specify the late modifier when it is not needed.
build thumb_up flutter
Learn more
unnecessary_library_directive
Avoid library directives unless they have documentation comments or annotations.
build
Learn more
unnecessary_library_name
Don't have a library name in a library declaration.
build thumb_up flutter
Learn more
unnecessary_new
Unnecessary new keyword.
build thumb_up flutter
Learn more
unnecessary_null_aware_assignments
Avoid null in null-aware assignment.
build thumb_up flutter
Learn more
unnecessary_null_aware_operator_on_extension_on_nullable
Unnecessary null aware operator on extension on a nullable type.
Learn more
unnecessary_null_checks
Unnecessary null checks.
science build
Learn more
unnecessary_null_in_if_null_operators
Avoid using null in ?? operators.
build thumb_up flutter
Learn more
unnecessary_nullable_for_final_variable_declarations
Use a non-nullable type for a final variable initialized with a non-nullable value.
build thumb_up flutter
Learn more
unnecessary_overrides
Don't override a method to do a super method invocation with the same parameters.
build circles thumb_up flutter
Learn more
unnecessary_parenthesis
Unnecessary parentheses can be removed.
build
Learn more
unnecessary_raw_strings
Unnecessary raw string.
build
Learn more
unnecessary_statements
Avoid using unnecessary statements.
Learn more
unnecessary_string_escapes
Remove unnecessary backslashes in strings.
build thumb_up flutter
Learn more
unnecessary_string_interpolations
Unnecessary string interpolation.
build thumb_up flutter
Learn more
unnecessary_this
Don't access members with this unless avoiding shadowing.
build thumb_up flutter
Learn more
unnecessary_to_list_in_spreads
Unnecessary toList() in spreads.
build thumb_up flutter
Learn more
unnecessary_unawaited
Unnecessary use of 'unawaited'.
build
Learn more
unnecessary_underscores
Unnecessary underscores can be removed.
build thumb_up flutter
Learn more
unreachable_from_main
Unreachable top-level members in executable libraries.
build
Learn more
unrelated_type_equality_checks
Equality operator == invocation with references of unrelated types.
circles thumb_up flutter
Learn more
unsafe_html
Avoid unsafe HTML APIs.
error
Learn more
unsafe_variance
Unsafe type: Has a type variable in a non-covariant position.
science
Learn more
use_build_context_synchronously
Do not use BuildContext across asynchronous gaps.
flutter
Learn more
use_colored_box
Use ColoredBox.
build
Learn more
use_decorated_box
Use DecoratedBox.
build
Learn more
use_enums
Use enums rather than classes that behave like enums.
build
Learn more
use_full_hex_values_for_flutter_colors
Prefer an 8-digit hexadecimal integer (for example, 0xFFFFFFFF) to instantiate a Color.
build flutter
Learn more
use_function_type_syntax_for_parameters
Use generic function type syntax for parameters.
build thumb_up flutter
Learn more
use_if_null_to_convert_nulls_to_bools
Use ?? operators to convert nulls to bools.
report build
Learn more
use_is_even_rather_than_modulo
Prefer intValue.isOdd/isEven instead of checking the result of % 2.
Learn more
use_key_in_widget_constructors
Use key in widget constructors.
build flutter
Learn more
use_late_for_private_fields_and_variables
Use late for private members with a non-nullable type.
science
Learn more
use_named_constants
Use predefined named constants.
build
Learn more
use_null_aware_elements
If-elements testing for null can be replaced with null-aware elements.
build thumb_up flutter
Learn more
use_raw_strings
Use raw string to avoid escapes.
build
Learn more
use_rethrow_when_possible
Use rethrow to rethrow a caught exception.
build thumb_up flutter
Learn more
use_setters_to_change_properties
Use a setter for operations that conceptually change a property.
Learn more
use_string_buffers
Use string buffers to compose strings.
Learn more
use_string_in_part_of_directives
Use string in part of directives.
build circles thumb_up flutter
Learn more
use_super_parameters
Use super-initializer parameters where possible.
science build thumb_up flutter
Learn more
use_test_throws_matchers
Use throwsA matcher instead of fail().
Learn more
use_to_and_as_if_applicable
Start the name of the method with to/_to or as/_as if applicable.
Learn more
use_truncating_division
Use truncating division.
build
Learn more
valid_regexps
Use valid regular expression syntax.
circles thumb_up flutter
Learn more
void_checks
Don't assign to void.
circles thumb_up flutter
Learn more