no-dupe-else-if
NOTE: this rule is part of the
recommended rule set.Enable full set in
deno.json:{
"lint": {
"rules": {
"tags": ["recommended"]
}
}
}Enable full set using the Deno CLI:
deno lint --rules-tags=recommended
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the
include or exclude array in deno.json:{
"lint": {
"rules": {
"include": ["no-dupe-else-if"],
"exclude": ["no-dupe-else-if"]
}
}
}Disallows using the same condition twice in an if/else if statement.
When you reuse a condition in an if/else if statement, the duplicate
condition will never be reached (without unusual side-effects) meaning this is
almost always a bug.
Invalid:
if (a) {}
else if (b) {}
else if (a) {} // duplicate of condition above
if (a === 5) {}
else if (a === 6) {}
else if (a === 5) {} // duplicate of condition above
Valid:
if (a) {}
else if (b) {}
else if (c) {}
if (a === 5) {}
else if (a === 6) {}
else if (a === 7) {}