Rules
General rules configuration is described here.
Rules are grouped by category to help you understand their purpose. Each rule has emojis denoting:
- ⚙️ - this rule is configurable
- 🛠 - some problems reported by this rule can be fixed by editor suggestions
- ⚠️ - this rule is deprecated and will be removed in the next major release
You can also suggest a rule!
Common 262 rules
Ensures that the order of named arguments in function, method, and constructor invocations matches the corresponding order of named parameters
Warns when a collection is accessed by a constant index inside a for loop
Warns when a private member of another class is used
Warns when an assignment is used inside a condition
Warns when an async function is invoked in non-async blocks
Warns when a record type declaration contains fields with void
, Never
or Null
Warns when a cascade expression is used after if null (??) binary expression without parentheses
Warns when an expression is casted to an extension type
Warns when a collection is checked for equality with another collection
Warns when a collection method is used with an expression of an unrelated type
Warns then a binary expression has a boolean constant that either makes the resulting value always the same or does not affect it
Warns when several conditions contradict each other
Warns when an import/export directive contains a double slash
Warns when a cascade expression has duplicate cascades
Warns when a collection has duplicate collection elements
Warns when a class or enum declaration has several constants with the same primitive values
Warns when a file has multiple exports
declarations with the same URI
Warns when a final variable has the same initializer as another variable in scope
Warns when a class has a mixin that is already present in that class's hierarchy.
Warns when a file has duplicate imports which differ only in name prefix
Warns when a LogicalOrPattern
or LogicalAndPattern
contains duplicate patterns
Warns when several switch cases have the same condition
Warns when a test case has multiple test assertions with the same expression and expected value
Warns when dynamic
type is used as variable type in declaration, return type of a function, etc
Warns when a collection literal in spread (...[]) has no elements
Warns when a test group does not have any test cases
Warns when both sides of a binary expression are the same
Warns when a condition has excessive expressions
Warns when an object pattern has an explicit field name
Warns when a variable is declared with an explicit type that can be omitted
Warns when a record type declaration contains a function type
Warns when a Future
is a target of the toString
method or is used in an interpolation
Warns when a generic type shadows an existing top-level (class, mixin, typedef or enum) declaration
Warns when the cyclomatic complexity of a method or function exceeds the configured threshold
Warns when a try / catch has multiple catch blocks with the same body
Warns when a return value of a method or function invocation or a class instance property access is not used
Warns when an extension type declaration does not have the implements
clause
Warns when an entrypoint export is imported inside the library src
folder
Warns when an inferrable type argument can be removed without affecting the code
Warns when a wildcard pattern has declaration keywords
Warns when a late final
variable is assigned multiple times in the same block
Warns when a function or method length (number of lines) exceeds the configured maximum
Warns when a file length (number of lines) exceeds the configured maximum
Warns when Map's .keys.contains
is used instead of containsKey
Warns when a method that should be invoked is passed as tear-off
Warns when Completer.completeError
is called without providing a stack trace
Warns when a enum constant is missing in a map declaration
Warns when a string equals to a variable name that is available in the current scope but is not wrapped into an interpolation
Configure a list of files that should have a corresponding test file
Warns when an incorrect matcher or literal is used to verify the target expression
Warns when a set literal is used in a wrong place
Warns when a record declaration contains both named and positional fields
Warns when multiple variable assignments are placed on the same line
Warns when an if statement or conditional expression have a negated condition that can be inverted
Suggests to refactor conditional expressions when the nesting level exceeds the configured threshold
Warns when the representation field of an extension type is also an extension type
Warns when a record type declaration contains a nested record type declaration
Warns when a switch expression contains another switch expression
Suggests moving all initialization logic to a separate method instead of the constructor
Warns when an exception class declaration has non-final fields
Warns when the non-null assertion operator !
(or “bang” operator) is used on a property access or method invocation
Warns when a toJson
method references a non-encodable object
Warns when an interpolation string contains a nullable value
Warns when a parameter with the default value is marked as nullable
Warns when the toString
method is called on a nullable value
Warns when a catch clause has only a rethrow
expression
Warns when an asynchronous function is used as an argument where a synchronous function is expected
Warns when an invocation has an argument that matches the parameter's default value.
Warns when an object is used as an argument to its own method
Warns when a record positional field is accessed via $
Checks for redundant async
in a method or function body
Checks for else
blocks that can be removed without changing semantics
Warns when a record positional field has a name
Warns when a @pragma('vm:prefer-inline')
annotation has no effect
Warns when a variable with the name that has only underscores (ex. _
, __
, etc.) is referenced
Warns when an extension type exposes a member that renames an existing representation field member
Suggests calling functions or methods with a void
return type separately from the return statement
Warns when a variable or a class instance field / property is assigned to itself
Warns when a comparison has both sides exactly the same
Warns when an extension declares a method with the name that is already used by the extension target
Warns when a declaration name shadows another declaration with the same name in the current scope
Checks for names within the scope that are very similar and thus confusing
Warns when a getter overrides a field that is already passed to the super constructor
Warns when a throw
expression is called inside a catch block
Warns when a thrown object does not implement toString
Warns when a public top-level member (except the entrypoint) is declared inside a test file
Warns when a late
field is not assigned a value
Warns when a stream subscription is not assigned to a variable
Warns when an error from a Future
inside a try / catch block might not be caught
Warns when a break
, continue
, return
or throw
are used unconditionally in a for loop
Warns when the @pragma
annotation has an unknown value
Warns when a .call()
invocation is unnecessary and can be simplified
Warns when a collection literal can be replaced by its first and only element
Checks for unnecessary conditional expressions
Suggests removing an unnecessary empty constructor for enum and class declarations
Warns when a enum constant has an unnecessary empty argument list
Suggests removing unnecessary extends
clauses that match default values for classes and type parameters
Warns when a return type of a declaration is unnecessary wrapped into a Future
Warns when a getter provides access to an existing final field without any additional logic
Warns when a return statement inside an if block is equal to the return statement after it
Warns when a late
variable is assigned in all code branches before use
Warns when the return type of a function or a method is declared nullable, but the function or method always return non-nullable value
Warns when a parent declaration is overridden by a declaration without an implementation
Warns when a value is reassigned to a variable without using the initial value
Warns when a return statement is unnecessary and can be removed
Warns when a constructor has an unnecessary super
invocation or when an invocation has an unnecessary super
prefix
Warns about unnecessary usage of the is
operator, and whereType
and whereNotNull
methods
Warns about unnecessary use of the as
operator and cast
method
Warns about unrelated usages of the is
operator and whereType
method
Warns about unrelated usages of the as
operator and cast
method
Warns when first
, last
, single
, firstWhere
, lastWhere
, singleWhere
or []
methods are used on Iterable
or its subclasses
Warns when the .reduce
collection method is called on a potentially empty collection
Warns when a variable is checked for non-nullable value, but is not used within the condition or then branch
Warns when an assignment is not used in the subsequent statements
Warns when a function or method declares unused generic types
Warns when a newly created object is not being used
Checks for unused parameters inside a function or method body
Warns when a weak cryptographic algorithm (ex. md5 or sha1) is used
Warns when a switch on the Enum
value has a wildcard pattern case
Warns when the configured method, field, constructor, or property name is used
Warns when a literal value is on the left hand side in a binary expressions
Warns when a field is not disposed in a class's dispose
method
Checks that double literals should begin with 0.
instead of just .
, and should not end with a trailing 0
Warns when a test
or testWidgets
name doesn't follow the configured pattern
Warns when a function with nullable return type returns only null
value
Warns when a function always returns the same constant value
Warns when an invocation's declaration is annotated with @Throws()
but the potential exception is not handled
Warns when a getter or setter do not access at least one field with the name that matches the getter or setter name
Warns when the file path in the test folder does not match the implementation file path in the lib folder
Warns when a positional field name does not match a variable name on destructuring assignment
Warns when a method or function declaration is missing the @useResult
annotation
Warns when a variable is declared in the outer block, but used only in the inner one
Warns when a variable does not depend on the outer loop and can be moved out
Warns when equal arguments are passed to a function or method invocation
Warns when an if statement contains another if statement with the same condition
Warns when a switch expression has cases with equal bodies
Warns when if statement has equal then and else statements or conditional expression has equal then and else expressions
Warns when number literals are used outside of named constants or variables
Warns when string literals are used outside of named constants or variables
Suggests adding abstract final
to classes with only static members to avoid them being instantiated or being used in inheritance
Warns when a collection's call chain can be rewritten to use .any()
or .every()
instead of .isEmpty
or .isNotEmpty
Recommends to use async/await
syntax to handle a Future
result instead of .then()
invocation
Suggests to prefix boolean variables, methods, fields and parameters with one of the configured prefixes
Warns when a @pragma('vm:prefer-inline')
annotation does not have a corresponding @pragma('dart2js:tryInline')
annotation
Warns when // ignore:
comments are left without any additional description of why this ignore is applied
Recommends to use a conditional expression instead of assigning to the same thing or return statement in each branch of an if statement
Suggests using .contains
instead of .indexOf
when checking for the presence of an element
Warns when a field with a Function type does not matched the configured name or a field with a non-Function type matches the configured name
Ensures a consistent name for the error parameter in catch
, then
, catchError
, listen
and handleError
Warns when a for loop increments a wrong variable
Warns when a declaration that returns a Future
has an incorrect return type
Warns when the callback handler name does not matched the configured one
Warns when the identifier name in variables, parameters, or enum constants is too short or too long
Warns when a JSON object type cast is done in an unsafe way that will throw at runtime
Warns when the setter parameter name does not match the configured one
Warns when a declaration that returns a Stream
has an incorrect return type
Warns if the file within /test
contains a main
, but the file name doesn't end with _test.dart
Warns when a declaration is missing or has an unnecessary @Throws()
annotation
Warns when a type name contains unexpected characters, does not start with an uppercase character, or is too short or too long
Warns when a class with no non-final fields has a non-constant constructor declaration
Since Dart 2.15 it's possible to use byName
method on enum values
prop instead of searching the value with firstWhere
Warns when a Function type does not specify the return type and arguments
Warns when a method that accepts type arguments has no arguments and no type arguments passed
Warns when an inline callback is passed as an argument to a function or method invocation
Suggests to convert a method that has no parameters and side-effects to a getter
Warns when a method or a function returns a variable declared right before the return statement
Warns when List.from()
factory is used instead of List.of()
Warns when a file name does not match the class name
Warns when a property access or a method invocation start with duplicated chains of other invocations / accesses inside a single function or method block
Suggests converting positional parameters to named parameters when a declaration has a certain number of positional parameters
Warns when a null check inside a collection literal can be replaced with a null-aware spread (...?)
Warns when a parent class implements hashCode
and ==
, but the child class does not implement them
Warns when an if null (??) has a binary expression without parentheses
Warns when a global constant does not start with a configured prefix
Warns when an extension type has a public representation field
Warns when an exception class declaration is not public
Warns when a Future is returned from a try / catch block without an await
Warns when several returns inside a function body can be replace with a single conditional expression
Warns when a patterns check for non-nullability can be simplified
Warns when a file contains more than one top-level declaration (class, mixin, extension, enum or extension type)
Warns when a more specific switch case is placed after a more general one
Suggests to use static class member instead of global constants, variables and functions
Suggests to use a switch statement or expression instead of conditionals with multiple enum values
Suggests to use a switch statement or expression instead of conditionals with sealed class instances
Warns when the second argument of an expect
or expectLater
is not a subclass of a Matcher
Checks for a trailing comma for arguments, parameters, enum values and collections
Warns when a variable is declared with the var
keyword instead of a type
Warns when the test name is not unique within the same test suite
Warns when the @visibleForTesting
annotation is applied to the class declaration
Warns when a dynamic
or Object
type is used instead of a wildcard pattern
Checks for unnecessary trailing commas for arguments, parameters, enum values and collections
Warns when an expression can be replaced by an existing variable with the same initializer
Flutter 44 rules
Warns when a class that matches the config does not declare a copyWith
method
Warns when an event listener is added but never removed
Suggests replacing the Border.all
constructor with the const Border.fromBorderSide
constructor
Suggests using the Spacer
widget instead of the Expanded
widget containing empty SizedBox/Container
widget
Checks if all parameters from the default constructor are added to the copyWith
method
Warns when an Image
widget is wrapped into an Opacity
widget
Warns when context.dependOnInheritedWidgetOfExactType
is transitively called from any invocation in initState
Warns when a TextFormField
, TextField
or EditableText
does not have at least one way to get the updated value
Warns when an Image
widget does not have a semanticLabel
Warns when a Widget
recursively uses itself
Warns when a method or function returns a Widget
or subclass of a Widget
Warns when a ListView
widget with shrinkWrap
parameter is wrapped in a Column
, Row
or another ListView
widget
Warns when a Column
, Row
, Flex
, Wrap
, SliverList
, SliverMainAxisGroup
or SliverCrossAxisGroup
widget has only one child
Warns when a State
has a constructor with non-empty body
Warns when an instance that has a dispose
method is not assigned to a variable
Warns when a GestureDetector
widget has no event handlers
Warns when a StatelessWidget
has an initialized final field
Warns when a widget's State
has unnecessary overrides
Warns when setState
is called inside initState
, didUpdateWidget
or build
methods and when it is called from a sync
method that is called inside those methods
Warns when a StatefulWidget
can be converted to a StatelessWidget
Warns when a widget is wrapped in a Padding
widget but has a padding setting by itself
Warns when a RenderObject
setter doesn't have an equality check for the new value
Warns when an updateRenderObject
method is absent or doesn't update all fields set in createRenderObject
Warns when a widget state field is not disposed in dispose
method
Warns when a FloatingActionButton
does not have a tooltip
specified
Suggests using a Center
widget instead of the Align
widget with no passed arguments
Suggests replacing the BorderRadius.circular
constructor with the const BorderRadius.all
constructor
Warns when MediaQuery.of
or MediaQuery.maybeOf
are used over dedicated methods (ex. sizeOf
)
Warns about inline callbacks in a widget tree and suggest to extract them to a widget method
Suggests using for-loop in arguments that accept a list of widgets
Suggests using a Padding
widget instead of the Container
widget with only padding
or margin
arguments
Warns when a file contains more than one widget
Suggests using the SizedBox.square
constructor when height
and width
arguments have the same value
Warns when a widget that returns a Sliver...
widget does not have a Sliver
prefix in its name
Warns when a Column
widget with only children
parameter is wrapped in a SingleChildScrollView
widget
Warns when a widget or widget state have public members (fields, methods, etc.)
Checks that super
calls in the initState
and dispose
methods are called in the correct order
Warns when setState
is called past an await point
Provider 6 rules
Warns when a Provider.value
returns a new instance instead of reusing an existing one
Warns when a watch
or select
methods are used outside of the build
method
Warns when a provided class with a dispose
method does not have this method called in the Provider dispose
callback
Warns when multiple nested Providers can be replaced with MultiProvider
instead
Suggests using context.read()
or context.watch()
instead of Provider.of(context)
Bloc 13 rules
Warns when a bloc declares multiple event handlers for the same event
Warns when a BlocBuilder
or BlocConsumer
does not specify the buildWhen
condition
Warns when a Bloc
event or a Cubit
method accept BuildContext
Warns when an async handler does not have isClosed
check before dispatching an event after an async gap
Suggests using `context.read()
or context.watch()
instead of BlocProvider.of(context)
Warns when a BlocProvider
/ BlocListener
/ RepositoryProvider
can be replace with a Multi
version
Warns when Bloc
state classes do not have a sealed
or final
modifier
Riverpod 7 rules
Warns when a Notifier
(or AsyncNotifier
) member is called inside the build
method
Warns when a Notifier
(or AsyncNotifier
) has a non-empty constructor
Warns when a ConsumerWidget
has an unused ref
and can be converted to a regular widget
Warns when an instance with a dispose
method created inside a provider does not have the dispose
method called in ref.onDispose
Equatable 2 rules
Warns when a field is not added to props
getter of a class that extends Equatable
or EquatableMixin
Flame 4 rules
Warns when a Vector2
is created inside a Component's update
method
Warns when a late final
variable is being initialized in the Component's onMount
method
Warns when a game is instantiated in a StatelessWidget
build method
Patrol 2 rules
Suggests using custom finders instead of find
in Patrol tests
Fake Async 1 rule
Get It 1 rule
Warns when a function is passed to registerSingleton
Flutter Hooks 6 rules
Warns when hooks inside the build method or other hooks are called conditionally
Warns when a hook is used outside the build method, other hooks or HookBuilder
Firebase Analytics 2 rules
Warns when the event name does not comply with Firebase limitations
Warns when the parameter name does not comply with Firebase limitations
GetX 5 rules
Warns when GetX Rx primitives are instantiated inside the build
method
Warns when GetX Rx primitives are declared as mutable variables
Checks that super
calls in the onStart
, onInit
, onClose
and onDelete
methods are called in the correct order
Pubspec 9 rules
pubspec-rules:
config section.Warns when a dependency version is listed not with the caret syntax
Warns when a dependency version is not specified as the exact version
Warns when a package version does not match the semantic versioning approach
Intl 6 rules
Warns when DateTime
, values are formatted with toString
instead of DateFormat.format()
Recommends to use ClassName_ClassMemberName
pattern for Intl methods name argument
Warns when int
, num
or double
values are formatted with toString
instead of NumberFormat.format()
Warns when an Intl
method invoked without an examples argument or has it incomplete
Easy Localization 1 rule
Angular 3 rules
Warns when a @Component
annotation has explicit false value for preserveWhitespace
Enforces Angular @Component
annotation arguments ordering
Prefer setting changeDetection: ChangeDetectionStrategy.OnPush
in Angular @Component
annotations