sonarjs/comma-or-logical-or-case
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/comma-or-logical-or-case": "error",
},
},
];Comma and logical OR operators should not be used in switch cases
switch (a) {
case 1,2: // Noncompliant; only 2 is ever handled by this case
doTheThing(a);
case 3 || 4: // Noncompliant; only '3' is handled
doThatThing(a);
case 5:
doTheOtherThing(a);
default:
console.log('Neener, neener!'); // this happens when a==1 or a == 4
}switch (a) {
case 1:
case 2:
doTheThing(a);
case 3:
case 4:
doThatThing(a);
case 5:
doTheOtherThing(a);
default:
console.log('Neener, neener!');
}Examples from the ESLint documentation.
sonarjs/comma-or-logical-or-case
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/comma-or-logical-or-case": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Dynamic code execution should not use user-controlled data
Regular expression quantifiers and character classes should be used concisely
Objects should not be created to be dropped immediately without being used
Chai assertions should have only one reason to succeed