Rules
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
Common 283 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
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 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 an if statement contains another if statement with the same condition
Warns when if statement has equal then and else statements or conditional expression has equal then and else expressions
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 several different property accesses can be replaced by a single class destructuring declaration
Warns when // ignore:
comments are left without any additional description of why this ignore is applied
Warns when Future.delayed
invocations do not have a descriptive comment
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 declaration that returns a Future
has an incorrect return type
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 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
Suggests using last
instead of list[list.length - 1]
or iterable.elementAt(iterable.length - 1)
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
Suggests using a redirecting constructor declared in the superclass
Warns when several returns inside a function body can be replace with a single conditional expression
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 converting an instance method to a static method if it does not reference any instance or inherited members
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 the @visibleForTesting
annotation is applied to the class declaration
Checks for unnecessary trailing commas for arguments, parameters, enum values and collections
Warns when there is an existing class or record destructuring that can be used instead of accessing the property directly
Warns when an expression can be replaced by an existing variable with the same initializer
Flutter 49 rules
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 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 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 an instance that has a dispose
method is not assigned to a variable
Warns when a StatelessWidget
has an initialized final field
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 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
Suggests using the Align
widget instead of the Container
widget with only the alignment
argument
Suggests using the 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 the Padding
widget instead of the Container
widget with only padding
or margin
arguments
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
Suggests using the spacing
argument of a Row
, Column
or Flex
instead of using SizedBox
widgets for adding gaps between children widgets
Suggests using the Transform
widget instead of the Container
widget with only the transform
argument
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 the referenced BuildContext
variable is not the closest BuildContext
Provider 6 rules
Warns when a Provider.value
returns a new instance instead of reusing an existing one
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 22 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 BlocProvider
returns an existing instance instead of creating a new one
Warns when a BlocProvider.value
returns a new instance instead of reusing an existing one
Warns when an async handler does not have isClosed
check before dispatching an event after an async gap
Warns when an emit
invocation receives the existing state instead of a newly created instance
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
Riverpod 7 rules
Warns when a Notifier
(or AsyncNotifier
) member is called inside the build
method
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 late final
variable is being initialized in the Component's onMount
method
Patrol 2 rules
Fake Async 1 rule
Get It 1 rule
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 parameter name does not comply with Firebase limitations
GetX 5 rules
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.Intl 6 rules
Warns when DateTime
, values are formatted with toString
instead of DateFormat.format()
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