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 included into the "recommended" preset
- ⚙️ - this rule is configurable
- 🛠 - some problems reported by this rule can be fixed by editor suggestions or by CLI fixes
You can also suggest a rule!
Common 279 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 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 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 a class or enum declaration has several constants with the same primitive values
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 a test case has multiple test assertions with the same expression and expected value
Warns when the dynamic
type is used as a variable type in a declaration, a function return type, etc.
Warns when a variable is declared with an explicit type that can be omitted
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 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 Completer.completeError
is called without providing a stack trace
Warns when a string equals to a variable name that is available in the current scope but is not wrapped into an interpolation
Warns when an incorrect matcher or literal is used to verify the target expression
Warns when a record declaration contains both named and positional fields
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
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 parameter with the default value is marked as nullable
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 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 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
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 public top-level member (except the entrypoint) is declared inside a test file
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 a collection literal can be replaced by its first and only element
Suggests removing an unnecessary empty constructor for enum and class declarations
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 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 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 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