no-duplicate-case
eslint
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"no-duplicate-case": "error",
},
},
];const a = 1,
one = 1;
switch (a) {
case 1:
break;
case 2:
break;
case 1: // duplicate test expression
break;
default:
break;
}
switch (a) {
case one:
break;
case 2:
break;
case one: // duplicate test expression
break;
default:
break;
}
switch (a) {
case "1":
break;
case "2":
break;
case "1": // duplicate test expression
break;
// …const a = 1,
one = 1;
switch (a) {
case 1:
break;
case 2:
break;
case 3:
break;
default:
break;
}
switch (a) {
case one:
break;
case 2:
break;
case 3:
break;
default:
break;
}
switch (a) {
case "1":
break;
case "2":
break;
case "3":
break;
// …Examples from the ESLint documentation.
no-duplicate-case
eslint
export default [
{
rules: {
"no-duplicate-case": "error",
},
},
];no-duplicate-case
eslint plugin · correctness
{
"rules": {
"no-duplicate-case": "error"
}
}suspicious/noDuplicateCase
suspicious · since 1.0.0
{
"linter": {
"rules": {
"suspicious": {
"noDuplicateCase": "error"
}
}
}
}Disallow empty character classes in regular expressions
Disallow empty destructuring patterns
Disallow unnecessary escape characters
Disallow assignments where both sides are exactly the same
Disallow control characters in regular expressions
Enforce comparing typeof expressions against valid strings