Skip to content

elseIfDuplicates

Reports duplicate conditions in if-else-if chains that make code unreachable.

✅ This rule is included in the ts logical and logicalStrict presets.

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.

if (
const status: any
status
=== "pending") {
const handlePending: any
handlePending
();
} else if (
const status: any
status
=== "active") {
const handleActive: any
handleActive
();
} else if (
const status: any
status
=== "pending") {
const handlePendingAgain: any
handlePendingAgain
();
}
if (
const isValid: any
isValid
&&
const isActive: any
isActive
) {
const processValid: any
processValid
();
} else if (
const isPending: any
isPending
) {
const processPending: any
processPending
();
} else if (
const isValid: any
isValid
&&
const isActive: any
isActive
) {
const processValidAgain: any
processValidAgain
();
}
if (
const count: any
count
=== 1) {
const handleOne: any
handleOne
();
} else if (
const count: any
count
=== 2) {
const handleTwo: any
handleTwo
();
} else if (
const count: any
count
=== 1) {
const handleOneAgain: any
handleOneAgain
();
}

This rule is not configurable.

If your project intentionally uses patterns that look like duplicate conditions but actually modify state behind-the-scenes, you might not want to enable this rule. For example, projects that modify state in computed object get() properties or use Proxy are often considered overly difficult to reason about for both humans and lint rules.

Made with ❤️‍🔥 around the world by the Flint team and contributors.