elseIfDuplicates
Reports duplicate conditions in if-else-if chains that make code unreachable.
✅ This rule is included in the ts logical
preset.
When an if-else-if chain contains duplicate conditions, the branch with the duplicate condition will never execute. This is because the earlier identical condition will always be evaluated first and match when true, preventing the duplicate condition from ever being reached. Duplicate conditions typically indicate a copy-paste error or a logic mistake in the code.
Examples
Section titled “Examples”if (status === "pending") { handlePending();} else if (status === "active") { handleActive();} else if (status === "pending") { handlePendingAgain();}
if (isValid && isActive) { processValid();} else if (isPending) { processPending();} else if (isValid && isActive) { processValidAgain();}
if (count === 1) { handleOne();} else if (count === 2) { handleTwo();} else if (count === 1) { handleOneAgain();}
if (status === "pending") { handlePending();} else if (status === "active") { handleActive();} else if (status === "completed") { handleCompleted();}
if (isValid && isActive) { processValid();} else if (isPending) { processPending();} else if (isValid && !isActive) { processInactive();}
if (count === 1) { handleOne();} else if (count === 2) { handleTwo();} else if (count === 3) { handleThree();}
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”This rule should always be enabled. Duplicate conditions in if-else-if chains represent unreachable code and are almost always a mistake.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noDuplicateElseIf
- ESLint:
no-dupe-else-if
- Oxlint:
eslint/no-dupe-else-if
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.