no-duplicate-case
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-duplicate-case"],
"exclude": ["no-duplicate-case"]
}
}
}Disallows using the same case clause in a switch statement more than once.
When you reuse a case test expression in a switch statement, the duplicate
case will never be reached meaning this is almost always a bug.
Invalid:
const someText = "a";
switch (someText) {
case "a": // (1)
break;
case "b":
break;
case "a": // duplicate of (1)
break;
default:
break;
}
Valid:
const someText = "a";
switch (someText) {
case "a":
break;
case "b":
break;
case "c":
break;
default:
break;
}