avoid-duplicate-switch-case-conditions
preset: recommended
Warns when several switch cases have the same condition.
Example
❌ Bad:
void fn(SomeClass param) {
final value = switch (param) {
Sub() when param.value.isEmpty => 1, // LINT
Sub() when param.value.isEmpty => 2, // LINT
_ => 3,
};
}
class SomeClass {
final String value;
const SomeClass(this.value);
}
class Sub extends SomeClass {
const Sub(super.value);
}
✅ Good:
void fn(SomeClass param) {
final value = switch (param) {
Sub() when param.value.isEmpty => 1,
Sub() when param.value.length == 2 => 2,
_ => 3,
};
}
class SomeClass {
final String value;
const SomeClass(this.value);
}
class Sub extends SomeClass {
const Sub(super.value);
}