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 266 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
Suggests using a regular variable declaration instead of a single field destructuring
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 pattern variable declaration does not affect the type of an existing local variable
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
Suggests moving await expressions to dedicated local variables
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