sonarjs/no-case-label-in-switch
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/no-case-label-in-switch": "error",
},
},
];"switch" statements should not contain non-case labels
switch (day) {
case MONDAY:
case TUESDAY:
WEDNESDAY: // instead of "case WEDNESDAY"
doSomething();
break;
...
}switch (day) {
case MONDAY:
break;
case TUESDAY:
foo:for(i = 0 ; i < X ; i++) {
/* ... */
break foo; // this break statement doesn't relate to the nesting case TUESDAY
/* ... */
}
break;
/* ... */
}switch (day) {
case MONDAY:
case TUESDAY:
case WEDNESDAY:
doSomething();
break;
...
}switch (day) {
case MONDAY:
break;
case TUESDAY:
compute(args); // put the content of the labelled "for" statement in a dedicated method
break;
/* ... */
}Examples from the ESLint documentation.
sonarjs/no-case-label-in-switch
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/no-case-label-in-switch": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Constructors should not contain asynchronous operations
Tests should not execute any code after "done()" is called
Collection size and array length comparisons should make sense