avoid_unnecessary_enum_prefix
v1.0.0 Warning Class Naming
This rule flags an enum constant that repeats the name of its own enum.
This rule is in the opinionated preset.
Why use this rule
Section titled “Why use this rule”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.
Dropping it also makes dot shorthands read properly: .active rather than .statusActive.
Two shapes are deliberately not reported: a constant named exactly like its enum (Status.status is the whole word, not a prefix), and one that merely starts with the same letters (statusable), since the prefix has to end at a word boundary.
See also: Enumerated types
enum Status { statusActive, statusArchived,}
// Every use repeats the type name.final state = Status.statusActive;enum Status { active, archived,}
final state = Status.active;Turning this rule off
Section titled “Turning this rule off”To disable this rule:
rules: avoid_unnecessary_enum_prefix: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”use_class_prefix— Require a name prefix for classes deriving from a configured type.match_class_name_pattern— Match class names against a regular expression.prefer_boolean_prefixes— Name booleans as questions.prefer_correct_callback_field_name— Name callbacks onSomething, the way Flutter does.