Skip to main content

avoid-wildcard-cases-with-enums

Warns when a switch on the Enum value has a wildcard pattern case.

Once a new constant is added to a Enum, the analyzer will highlight all cases where this new constant should be used, unless there is a wildcard case.

Example

❌ Bad:

enum MyEnum { first, second }

void someFn() {
final value = MyEnum.first;

final result = switch (value) {
MyEnum.first => 1,
// LINT: Avoid wildcard cases with 'Enums'.
// Try enumerating all the possible values of the switch expression.
_ => 2,
};
}

✅ Good:

enum MyEnum { first, second }

void someFn() {
final value = MyEnum.first;

final result = switch (value) {
MyEnum.first => 1,
MyEnum.second => 2, // Correct, all enum constants are listed
};
}