Skip to content

no-dupe-else-if

Reports an else if whose condition cannot be true at that point: it repeats a condition of an earlier branch of the chain (if (a) {} else if (a) {}), or each operand of its || is a whole earlier condition or an operand of an earlier || (if (a || b) {} else if (a) {}). A condition that is only implied by an earlier one (a && b after a) is not found.

If an earlier condition was true its branch ran, and if it was false the same condition is false again, so the later branch never runs. This is nearly always a copy-paste slip where the condition was not changed, and the code the author meant to run is the dead one.

To fix, correct the condition or remove the branch.

Reported
...
if (a) {} else if (b) {} else if (a) {}
if (a || b) {} else if (a) {} else if (b && c) {}
if (a && b) {} else if (a) {} else if (b && a) {}
...
js:
lint:
rules:
no-dupe-else-if: warn # off, warn (default), error

Enabled by the presets: js/eslint-recommended, js/biome-recommended, js/oxlint.

Suppress one line with sudsy-disable-next-line no-dupe-else-if in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
eslint no-dupe-else-if full