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
Common
Enforces named argument order in function and constructor invocations to be the same as corresponding named parameter declaration order.
Warns when a private member of another class is used.
Warns when an async function is invoked in non-async blocks.
Warns when a pattern contains a void
,Never
or Null
type.
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 multiple nested if statements can be merged into one.
Avoid using collection methods with unrelated types, such as accessing a map of integers using a string key.
Warns when an import/export directive contains a double slash.
Warns when a file has multiple exports
declarations with the same URI.
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 duplicated patterns.
Warns when dynamic
type is used as variable type in declaration, return type of a function, etc.
Warns when both sides of a binary expression are the same.
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 and existing top-level (class, mixin, typedef or enum) declaration.
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 entrypoint export is imported inside the library src
folder.
Warns when a wildcard pattern has declaration keywords.
Warns when a field or variable is declared with a late
keyword.
Warns when a function or method has a too long parameter list.
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 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.
Warns when a wildcard pattern is used in the wrong context.
Warns when a method that should be invoked is passed as tear-off.
Warns when a parameter's field or setter is reassigned.
Warns when an if statement or conditional expression have a negated condition that can be inverted.
Warns when a record type declaration contains a nested record type declaration.
Warns when a Stream
type contains a Future
or vice versa.
Warns when a switch expression contains another switch expression.
Warns when a switch case body has another switch statement.
Warns when a string literal contains non ascii characters.
Warns when non null assertion operator !
(or “bang” operator) is used for a property access or method invocation. The operator check works at runtime and it may fail and throw a runtime exception.
Warns when an interpolation string contains a nullable value.
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 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 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.
Checks for names within the scope that are very similar and thus confusing.
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 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 .call()
invocation is unnecessary and can be simplified.
Warns when a return type of a declaration is unnecessary wrapped into a Future
.
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 value is reassigned to a variable without using the initial value.
Warns when a return statement is unnecessary and can be removed.
Warns about unnecessary usage of is
and whereType
operators.
Warns when first
, last
, single
, firstWhere
, lastWhere
, singleWhere
or []
methods are used on Iterable
or its subclasses.
Warns when a function or method declares unused generic types.
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 literal value is on the left hand side in a binary expressions.
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.
Ensures consistent alphabetical order of String
keys inside a map.
Warns when a positional field name does not match a variable name on destructuring assignment.
Warns when a record type should be moved to a typedef.
Warns when a variable is declared in the outer block, but used only in the inner one.
Enforces a blank line between statements and return in a block.
Warns on comparison to a boolean literal, as in x == true
.
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 against using number literals outside of named constants or variables.
Ensures consistent alphabetical order of parameters by their names.
Recommends to use async/await
syntax to handle a Future
result instead of .then()
invocation.
Warns when // ignore:
comments are left without any additional description 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.
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 an identifier name length is very short or long.
Warns when a JSON object type cast is done in an unsafe way that will throw at runtime.
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
.
Type name should only contain alphanumeric characters, start with an uppercase character and span between min-length and max-length characters in length.
Warns when a class with no non-final fields has a non-constant constructor declaration.
Warns when an if statement can be transformed to an early return.
Since Dart 2.15 it's possible to use byName
method on enum values
prop instead of searching the value with firstWhere
.
Warns when parameter names in function types are omitted.
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 property access or a method invocation start with duplicated chains of other invocations / accesses inside a single function or method block.
Warns when a declaration has a boolean positional parameter.
Warns when an if null (??) has a binary expression without parentheses.
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.
Suggests to use static class member instead of global constants, variables and functions.
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 a FutureOr
is not unwrapped before being used.
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.
Flutter
Warns when a class that matches the config does not declare a copyWith
method.
Warns when an event listener is added but never removed.
Checks if all the parameters from the default constructor are included in the copyWith
method.
Warns when context.dependOnInheritedWidgetOfExactType
is transitively called from any invocation in initState
.
Warns when an Image
widget does not have a semanticLabel
.
Warns when a Widget is recursively used within the same Widget.
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 State
has a constructor with non-empty body.
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 settings 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.
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.
Warns when a file contains more than a single widget.
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.
Provider
Lint rules for the Provider package.
Warns when a Provider.value
returns a new instance instead of reusing an existing one.
Warns when a read
method is used inside of the build
method.
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.
Bloc
Lint rules for the Bloc package.
Warns when a Bloc
has public methods except the overridden ones.
Warns when an async handler does not have isClosed
check before dispatching an event after an async gap.
Warns when a Bloc
is provided not with a BlocProvider
.
Warns when a BlocProvider
/ BlocListener
/ RepositoryProvider
can be replace with a Multi
version.
Equatable
Lint rules for the Equatable package.
Warns when a class that matches the config does not extend Equatable
.
Warns when a field is not added to props
getter of a class that extends Equatable
or EquatableMixin
.
Flame
Lint rules for the Flame package.
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 Component's onLoad
method can be made sync.
Warns when a game is instantiated in a stateless widget build method.
Patrol
Lint rules for the Patrol package.
Suggests using custom finders instead of find
in Patrol tests.
Suggests using symbols instead of string keys in Patrol tests.
Fake Async
Lint rules for the Fake Async package.
Warns when an async callback is passed to FakeAsync
.
Pubspec
Pub rules should be added to the pubspec-rules:
config section.
Warns when a pubspec file has the dependency_overrides
section.
Warns when a dependency version is listed not with the caret syntax.
Warns when a package name does not match the config.
Warns when a screenshots section has incorrect entries.
Warns when a pubspec file does not have publish_to: none
config.
Warns when a package version does not match the semantic versioning approach.
Intl
Lint rules for the Intl package.
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 a Intl
method invoked without a description.
Warns when the Intl.message()
invocation has incorrect args.
Angular
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.