BACK TO LIST

Dart rules

Codiga provides multiple sets of rules for 12+ languages. Below we provide a link and a description for all the rules supported by our platform. Note that not all the rules are being listed and described below.

ALWAYS_DECLARE_RETURN_TYPES

Code style
Error

Method should have return type

always_specify_types

Code style
Informational

Always specify types

ARGUMENT_TYPE_NOT_ASSIGNABLE

Code style
Warning

Invalid assignments

ASSET_DOES_NOT_EXIST

Code style
Warning

Asset does not exists

AVOID_BOOL_LITERALS_IN_CONDITIONAL_EXPRESSIONS

Code style
Informational

Avoid bool literals in condition

AVOID_CLASSES_WITH_ONLY_STATIC_MEMBERS

Code style
Informational

Avoid defining a class that contains only static members.

AVOID_ESCAPING_INNER_QUOTES

Code style
Informational

Avoid escaping inner quotes by converting surrounding quotes.

AVOID_FUNCTION_LITERALS_IN_FOREACH_CALLS

Code style
Informational

Avoid using `forEach` with a function literal.

avoid_init_to_null

Code style
Informational

Don't explicitly initialize variables to null.

AVOID_POSITIONAL_BOOLEAN_PARAMETERS

Code style
Informational

Avoid positional boolean parameters.

AVOID_PRINT

Code style
Error

Avoid `print` calls in production code.

AVOID_REDUNDANT_ARGUMENT_VALUES

Code style
Informational

Avoid redundant argument values.

AVOID_RETURN_TYPES_ON_SETTERS

Code style
Informational

Avoid return types on setters.

AVOID_UNNECESSARY_CONTAINERS

Code style
Informational

Avoid unnecessary containers.

AVOID_VOID_ASYNC

Code style
Informational

Avoid async functions that return void.

AVOID_WEB_LIBRARIES_IN_FLUTTER

Code style
Informational

Avoid using web-only libraries outside Flutter web plugin packages.

AWAIT_ONLY_FUTURES

Code style
Informational

await' should only apply to futures

BODY_MIGHT_COMPLETE_NORMALLY

Code style
Warning

The body might complete normally

CAMEL_CASE_TYPES

Code style
Informational

Name types using UpperCamelCase.

CAST_NULLABLE_TO_NON_NULLABLE

Code style
Informational

Don't cast a nullable value to a non nullable type.

CAST_TO_NON_TYPE

Code style
Warning

The name isn't a type

close_sinks

Code style
Informational

Close instances of `dart.core.Sink`.\n

CONST_INITIALIZED_WITH_NON_CONSTANT_VALUE

Code style
Warning

Const variables must be initialized with a constant value.

CONST_WITH_NON_CONSTANT_ARGUMENT

Code style
Warning

Arguments of a constant creation must be constant expressions.

COULD_NOT_INFER

Code style
Warning

Cannot infer type

CREATION_WITH_NON_TYPE

Code style
Warning

The name 'BubbleStyle' isn't a class.\n

DEAD_CODE

Code style
Informational

Dead code.

DEAD_CODE_ON_CATCH_SUBTYPE

Code style
Informational

Dead code on catch subtype.

DEAD_NULL_AWARE_EXPRESSION

Code style
Informational

The left operand can't be null.

DEFAULT_LIST_CONSTRUCTOR

Code style
Warning

The default 'List' constructor isn't available when null safety is enabled.

DEPEND_ON_REFERENCED_PACKAGES

Code style
Informational

Depend on referenced packages.

DEPRECATED_MEMBER_USE

Code style
Informational

Member is deprecated and shouldn't be used. This property is no longer used

DIRECTIVES_ORDERING

Code style
Informational

Import ordering

DUPLICATE_IMPORT

Code style
Informational

Duplicate import.

EMPTY_CATCHES

Code style
Informational

Avoid empty catch blocks.

empty_constructor_bodies

Code style
Informational

Use `;` instead of `{}` for empty constructor bodies.

empty_statements

Code style
Informational

Detect empty statements (dead code)

EOL_AT_END_OF_FILE

Code style
Informational

Put a single newline at end of file.

EXPECTED_TOKEN

Code style
Warning

Expected to find '['.

EXTENDS_NON_CLASS

Code style
Warning

Classes can only extend other classes.

EXTRA_POSITIONAL_ARGUMENTS

Code style
Warning

Too many positional arguments.

FILE_NAMES

Code style
Informational

Name source files using `lowercase\_with\_underscores`.

GETTER_NOT_SUBTYPE_SETTER_TYPES

Code style
Warning

Invalid return type

HASH_AND_EQUALS

Code style
Informational

Override `hashCode` if overriding `==`

ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE

Code style
Error

Illegal assignment to non-assignable expression.

implementation_imports

Code style
Informational

Don't import implementation files from another package.

IMPLEMENTS_NON_CLASS

Code style
Warning

Classes and mixins can only implement other classes and mixins.

IMPORT_OF_LEGACY_LIBRARY_INTO_NULL_SAFE

Code style
Informational

Legacy library

INCLUDE_FILE_NOT_FOUND

Code style
Warning

Include file not found

INVALID_ANNOTATION_TARGET

Code style
Informational

Invalid annotation target

INVALID_ASSIGNMENT

Code style
Warning

Invalid assignments

INVALID_CONSTANT

Code style
Warning

Invalid constant value

INVALID_NULL_AWARE_OPERATOR

Code style
Informational

The receiver can't be null because of short-circuiting

INVALID_OVERRIDE

Code style
Warning

Invalid override

INVALID_USE_OF_PROTECTED_MEMBER

Code style
Informational

Invalid use of protected members

INVARIANT_BOOLEANS

Code style
Informational

Conditions should not unconditionally evaluate to `true` or to `false`.

JOIN_RETURN_WITH_ASSIGNMENT

Code style
Informational

Join return statement with assignment when possible.

LIBRARY_PREFIXES

Code style
Informational

Use `lowercase\_with\_underscores` when specifying a library prefix.

LIST_ELEMENT_TYPE_NOT_ASSIGNABLE

Code style
Warning

List element type not assignable

MISSING_ASSIGNABLE_SELECTOR

Code style
Error

Missing selector

MISSING_DEFAULT_VALUE_FOR_PARAMETER

Code style
Warning

Missing default value for parameter

MISSING_ENUM_CONSTANT_IN_SWITCH

Code style
Informational

Missing case clause for 'null'.

MISSING_IDENTIFIER

Code style
Warning

Expected an identifier.

MISSING_REQUIRED_ARGUMENT

Code style
Error

Missing required argument

MISSING_REQUIRED_PARAM

Code style
Warning

Missing required parameters

MISSING_RETURN

Code style
Informational

Missing return value

MIXIN_OF_NON_CLASS

Code style
Warning

Classes can only mix in mixins and classes.

MIXIN_WITH_NON_CLASS_SUPERCLASS

Code style
Warning

Mixin can only be applied to class.

MUST_BE_IMMUTABLE

Code style
Informational

Must be immutable

MUST_CALL_SUPER

Code style
Informational

This method overrides a method annotated as '@mustCallSuper' in 'State'

NEW_WITH_UNDEFINED_CONSTRUCTOR_DEFAULT

Code style
Warning

The class doesn't have a default constructor.

NO_DEFAULT_SUPER_CONSTRUCTOR

Code style
Error

No default super constructor

NON_ABSTRACT_CLASS_INHERITS_ABSTRACT_MEMBER

Code style
Warning

Missing concrete implementations of methods

NON_BOOL_CONDITION

Code style
Warning

Conditions must have a static type of 'bool'

NON_CONSTANT_CASE_EXPRESSION

Code style
Warning

Case expressions must be constant

NON_CONSTANT_DEFAULT_VALUE

Code style
Warning

The default value of an optional parameter must be constant

non_constant_identifier_names

Code style
Informational

Name non-constant identifiers using lowerCamelCase

NON_CONSTANT_LIST_ELEMENT

Code style
Warning

The values in a const list literal must be constants

NON_CONSTANT_MAP_VALUE

Code style
Warning

The values in a const map literal must be constant

NON_TYPE_AS_TYPE_ARGUMENT

Code style
Warning

The name isn't a type so it can't be used as a type argument

NON_TYPE_IN_CATCH_CLAUSE

Code style
Warning

The name isn't a type and can't be used in an on-catch clause.

NOOP_PRIMITIVE_OPERATIONS

Code style
Informational

Noop primitive operations.

NOT_ASSIGNED_POTENTIALLY_NON_NULLABLE_LOCAL_VARIABLE

Code style
Warning

The non-nullable local variable must be assigned before it can be used.

NOT_INITIALIZED_NON_NULLABLE_INSTANCE_FIELD

Code style
Warning

Non-nullable instance field must be initialized.

NOT_INITIALIZED_NON_NULLABLE_VARIABLE

Code style
Warning

The non-nullable variable must be initialized.

NULLABLE_TYPE_IN_CATCH_CLAUSE

Code style
Informational

A potentially nullable type can't be used in an 'on' clause because it isn't valid to throw a nullable expression.

OVERRIDDEN_FIELDS

Code style
Informational

Don't override fields.

OVERRIDE_ON_NON_OVERRIDING_MEMBER

Code style
Informational

The field doesn't override an inherited getter or setter.

POSITIONAL_AFTER_NAMED_ARGUMENT

Code style
Warning

Positional arguments must occur before named arguments.

PREFER_CONST_CONSTRUCTORS

Code style
Informational

Prefer const with constant constructors.

PREFER_CONST_CONSTRUCTORS_IN_IMMUTABLES

Code style
Informational

Prefer declaring const constructors on `@immutable` classes

PREFER_CONST_DECLARATIONS

Code style
Error

Prefer const over final for declarations

PREFER_CONST_LITERALS_TO_CREATE_IMMUTABLES

Code style
Informational

Prefer const literals as parameters of constructors on @immutable classes.

PREFER_FINAL_IN_FOR_EACH

Code style
Informational

Prefer final in for-each loop variable if reference is not reassigned.

PREFER_FINAL_LOCALS

Code style
Error

Prefer final for variable declarations if they are not reassigned.

PREFER_IF_ELEMENTS_TO_CONDITIONAL_EXPRESSIONS

Code style
Informational

Prefer if elements to conditional expressions where possible.

PREFER_IF_NULL_OPERATORS

Code style
Informational

Prefer using if null operators.

PREFER_INITIALIZING_FORMALS

Code style
Informational

Use initializing formals when possible.

PREFER_INTERPOLATION_TO_COMPOSE_STRINGS

Code style
Informational

Use interpolation to compose strings and values.

PREFER_IS_EMPTY

Code style
Informational

Use isEmpty instead of length\n

PREFER_IS_NOT_EMPTY

Code style
Informational

Use `isNotEmpty` for Iterables and Maps.

PREFER_NULL_AWARE_METHOD_CALLS

Code style
Informational

Prefer null aware method calls.

PREFER_TYPING_UNINITIALIZED_VARIABLES

Code style
Informational

Prefer typing uninitialized variables and fields.

REDIRECT_TO_NON_CLASS

Code style
Error

Name isn't a type and can't be used in a redirected constructor.

REQUIRE_TRAILING_COMMAS

Code style
Informational

Missing a required trailing comma.

RETURN_OF_INVALID_TYPE

Code style
Warning

Invalid return type

RETURN_OF_INVALID_TYPE_FROM_CLOSURE

Code style
Warning

Invalid return type from closure

SIZED_BOX_FOR_WHITESPACE

Code style
Informational

SizedBox for whitespace.

SORT_CHILD_PROPERTIES_LAST

Code style
Error

Sort child properties last in widget instance creations.

SORT_PUB_DEPENDENCIES

Code style
Informational

Sort pub dependencies.

TYPE_ANNOTATE_PUBLIC_APIS

Code style
Error

Type annotate public APIs.

TYPE_ARGUMENT_NOT_MATCHING_BOUNDS

Code style
Error

Type arguments do not match bounds

TYPE_TEST_WITH_UNDEFINED_NAME

Code style
Warning

Undefined name

UNCHECKED_USE_OF_NULLABLE_VALUE

Code style
Warning

Method can't be unconditionally invoked because the receiver can be 'null'.

UNDEFINED_CONSTRUCTOR_IN_INITIALIZER

Code style
Warning

Undefined constructor

UNDEFINED_GETTER

Code style
Warning

Undefined getter

UNDEFINED_NAMED_PARAMETER

Code style
Warning

Named parameter undefined

UNDEFINED_OPERATOR

Code style
Error

Undefined operator

UNDEFINED_SETTER

Code style
Warning

Undefined setter

UNDEFINED_SUPER_MEMBER

Code style
Warning

Undefined super member

unnecessary_brace_in_string_interps

Code style
Informational

Avoid using braces in interpolation when not needed.

UNNECESSARY_CAST

Code style
Informational

Unnecessary cast.

UNNECESSARY_NEW

Code style
Informational

Unnecessary new keyword.

UNNECESSARY_NON_NULL_ASSERTION

Code style
Warning

Uneccessary non null assertion

UNNECESSARY_NULL_CHECKS

Code style
Informational

Unnecessary null checks

UNNECESSARY_NULL_COMPARISON

Code style
Informational

The operand can't be null

UNNECESSARY_PARENTHESIS

Code style
Informational

Unnecessary parenthesis

unnecessary_statements

Code style
Informational

Avoid using unnecessary statements

UNNECESSARY_STRING_INTERPOLATIONS

Code style
Informational

Unnecessary string interpolation

UNNECESSARY_THIS

Code style
Error

Unecessary this

UNSUPPORTED_OPERATOR

Code style
Error

The '===' operator is not supported

UNUSED_CATCH_CLAUSE

Code style
Informational

Unused catch clause

UNUSED_CATCH_STACK

Code style
Informational

Stack trace not used

UNUSED_ELEMENT

Code style
Informational

Unused element

UNUSED_FIELD

Code style
Informational

Unused fiel

UNUSED_IMPORT

Code style
Informational

Unused import

UNUSED_LABEL

Code style
Informational

Unused label

UNUSED_LOCAL_VARIABLE

Code style
Informational

Unused local variable

URI_HAS_NOT_BEEN_GENERATED

Code style
Warning

URI has not been generated

USE_BUILD_CONTEXT_SYNCHRONOUSLY

Code style
Informational

Use build context synchronuously

USE_LATE_FOR_PRIVATE_FIELDS_AND_VARIABLES

Code style
Informational

Use late for private members with non-nullable type.

USE_NAMED_CONSTANTS

Code style
Informational

Use named constants

USE_OF_VOID_RESULT

Code style
Error

Use of void results

USE_STRING_BUFFERS

Code style
Informational

Use string buffers to compose strings

NO_LEADING_UNDERSCORES_FOR_LOCAL_IDENTIFIERS

Code style
Warning

Avoid leading underscores for local identifiers.

Learn more

CONSTANT_IDENTIFIER_NAMES

Code style
Warning

Prefer using lowerCamelCase for constant names.

DIRECTIVE_AFTER_DECLARATION

Code style
Informational

Directives must appear before any declarations.

FLUTTER_STYLE_TODOS

Code style
Informational

Use Flutter TODO format.

NO_LEADING_UNDERSCORES_FOR_LIBRARY_PREFIXES

Code style
Informational

Avoid leading underscores for library prefixes.

INVALID_FACTORY_NAME_NOT_A_CLASS

Code style
Informational

The name of a factory constructor must be the same as the name of the immediately enclosing class.

We use cookies to improve your site experience, including analytics cookies to understand how you use our product and design better experiences. Please read our Cookie Policy.