Skip to content

avoid_unnecessary_enum_prefix

v1.0.0 Warning Class Naming

Flags an enum constant that repeats the name of its own enum.

enum Status { statusActive } reads as Status.statusActive at every call site, where the type already says Status. The prefix is a habit carried over from languages whose enum constants share one namespace; Dart scopes them to the enum, so it buys nothing and lengthens every use.

This rule is in the opinionated preset, and takes no configuration.

enum Status {
statusActive,
statusArchived,
}
// Every use repeats the type name.
final state = Status.statusActive;
enum Status {
active,
archived,
}
final state = Status.active;

Dot shorthands read properly once the prefix is gone

Section titled “Dot shorthands read properly once the prefix is gone”

Dropping it is what makes Dart 3.10’s shorthand usable — .active rather than .statusActive:

enum Status { active, archived }
void setStatus(Status status) {}
void main() {
setStatus(.active);
}

A constant named exactly like its enum is left alone

Section titled “A constant named exactly like its enum is left alone”

Status.status is the whole word, not a prefix, so there is nothing to strip:

enum Status {
status, // Accepted
active,
}

A constant that merely starts with the same letters is not prefixed by them:

enum Status {
statusable, // Accepted — `able` does not begin a new word
statusActive, // LINT — `Active` does
}

Enums only. A class of static const values used as an enum substitute is not checked.

No quick fix. Renaming a constant touches every call site and every switch arm that names it, which is a rename refactoring rather than a one-file edit.

See also: Enumerated types

To disable this rule:

many_lints.yaml
rules:
avoid_unnecessary_enum_prefix: false

To keep the rule on but skip certain paths, use per-rule exclude.