avoid-duplicate-switch-case-conditions
- Group
- Correctness
- Path
lint/correctness/avoid-duplicate-switch-case-conditions- Default
- On (recommended)
- Origin
- Falcon
- Rule
- 54 of 512
Flags repeated when guards on syntactically identical switch patterns.
Repeating a pattern and guard usually leaves the later arm unreachable.
This rule compares guard and pattern tokens, preserving literal contents;
Constant, literal, logical-or, and parenthesized patterns are left to
no-duplicate-case-values. Different patterns may legitimately share a guard.
Guards must use stable primitive variable reads and built-in comparisons;
unknown getters, overloaded operators, and calls are not considered repeatable.
The immutable String properties length, isEmpty, and isNotEmpty are
supported on stable String variables.
Invalid
int f(Object value, bool ready, int count) => switch (value) {
int() when ready => 1,
int() when ready => 2,
String() when count > 1 => 3,
String() when count>1 => 4,
bool() when !ready => 5,
bool() when !ready => 6,
double() when count == 2 => 7,
double() when count == 2 => 8,
_ => 0,
};
void g(Object value, bool ready) {
switch (value) {
case int() when ready: break;
case int() when ready: break;
default: break;
}
}
int stringGuards(Object value, String text) => switch (value) {
int() when text.isEmpty => 1,
int() when text.isEmpty => 2,
String() when text.length > 2 => 3,
String() when text.length > 2 => 4,
bool() when text.isNotEmpty => 5,
bool() when text.isNotEmpty => 6,
_ => 0,
}; int() when ready => 1, int() when ready => 2, String() when count > 1 => 3, String() when count>1 => 4, bool() when !ready => 5, bool() when !ready => 6, double() when count == 2 => 7, double() when count == 2 => 8, case int() when ready: break; case int() when ready: break; int() when text.isEmpty => 1, int() when text.isEmpty => 2, String() when text.length > 2 => 3, String() when text.length > 2 => 4, bool() when text.isNotEmpty => 5, bool() when text.isNotEmpty => 6,Valid
bool next() => true;
int f(Object value, bool ready, int count) => switch (value) {
int() when ready => 1,
String() when ready => 2,
int() when !ready => 3,
double() when count > 1 => 4,
double() when count > 2 => 5,
bool() when next() => 6,
bool() when next() => 7,
_ => 0,
};
int g(String value) => switch (value) {
'a b' => 1,
'ab' => 2,
_ => 3,
};
bool get changing => next();
const code = 1;
int getterGuard(Object value) => switch (value) {
int() when changing => 1,
int() when changing => 2,
_ => 0,
};
class Flags {
bool get ready => next();
}
int customGetter(Object value, Flags flags) => switch (value) {
int() when flags.ready => 1,
int() when flags.ready => 2,
_ => 0,
};
// Constant cases are owned by no-duplicate-case-values, even with guards.
int literalCases(int value, bool ready) => switch (value) {
1 when ready => 1,
1 when ready => 2,
code when !ready => 3,
code when !ready => 4,
2 || 3 when ready => 5,
2 || 3 when ready => 6,
(4) when ready => 7,
(4) when ready => 8,
_ => 0,
};
int dynamicGuard(Object value, dynamic unknown) => switch (value) {
int() when unknown == 1 => 1,
int() when unknown == 1 => 2,
_ => 0,
};
class StoredGuard {
final bool ready = true;
final String text = '';
int guard(Object value) => switch (value) {
int() when ready => 1,
int() when ready => 2,
String() when text.isEmpty => 3,
String() when text.isEmpty => 4,
_ => 0,
};
}
class ChangingGuard extends StoredGuard {
@override
bool get ready => next();
@override
String get text => next() ? '' : 'changing';
}
bool globalReady = true;
int globalGuard(Object value) => switch (value) {
int() when globalReady => 1,
int() when globalReady => 2,
_ => 0,
};Configure avoid-duplicate-switch-case-conditions
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"avoid-duplicate-switch-case-conditions": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/avoid-duplicate-switch-case-conditions: <reason>More correctness rules
- avoid-duplicate-test-assertionsrecommendedtest
Reports repeated identical, side-effect-free assertions in a straight-line block.
- avoid-dynamic-calls
avoid_dynamic_callsrecommendedAvoid method calls or property accesses on a
dynamictarget. - avoid-emit-outside-blocrecommendedbloc
Flags external calls and tear-offs of a Bloc or Cubit's
emitmethod. - avoid-empty-setstaterecommendedflutter
Avoid setState callbacks with empty block bodies.
- avoid-empty-test-groupstest
Reports inline framework groups without any test registrations.
- avoid-global-state
avoid-global-stateDisallow mutable global and static state.
- avoid-hooks-outside-buildrecommendedflutter_hooks
Flags confirmed Flutter hooks outside hook builds, custom hooks, and HookBuilder/HookConsumer builders.
- avoid-incorrect-image-opacityflutter
Flags Opacity directly wrapping a Flutter Image, including named constructors.