Skip to content

no_equal_conditions

v1.0.0 Warning Control Flow

This rule flags an if/else if chain that tests the same condition twice.

The second test can never be reached: the first branch already took every case it would have matched. Whatever the repeated branch does is dead code, and the case it was meant to handle silently falls through to else — so the bug shows up as a missing behaviour rather than an error.

It is a copy-paste result: a branch duplicated and its body edited while its condition was left alone.

Two independent if statements testing the same thing are not reported — the first may have changed the state the second reads. Only one chain is compared. A pattern case (if (x case ...)) is skipped, since two clauses that read alike need not test the same thing.

if (status.isPending) {
showSpinner();
} else if (status.isPending) { // never reached
showRetry();
}
if (status.isPending) {
showSpinner();
} else if (status.isFailed) {
showRetry();
}

This rule is in the recommended preset, so it is on with preset: recommended or preset: opinionated.

To disable this rule:

many_lints.yaml
rules:
no_equal_conditions: false

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