sonarjs/no-duplicated-branches
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/no-duplicated-branches": "error",
},
},
];Two branches in a conditional structure should not have exactly the same implementation
switch (i) {
case 1:
doFirstThing();
doSomething();
break;
case 2:
doSomethingDifferent();
break;
case 3: // Noncompliant; duplicates case 1's implementation
doFirstThing();
doSomething();
break;
default:
doTheRest();
}
if (a >= 0 && a < 10) {
doFirstThing();
doTheThing();
}
else if (a >= 10 && a < 20) {
doTheOtherThing();
}
else if (a >= 20 && a < 50) {
doFirstThing();
doTheThing(); // Noncompliant; duplicates first condition
}
else {
doTheRest();
}The documentation shows no correct example for this rule.
Examples from the ESLint documentation.
sonarjs/no-duplicated-branches
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/no-duplicated-branches": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Test titles should be unique within the same suite
Collection elements should not be replaced unconditionally
Parameterized tests should not contain duplicate test cases
Reluctant quantifiers in regular expressions should be followed by an expression that can't match the empty string
Union and intersection types should not include duplicated constituents
Alternation in regular expressions should not contain empty alternatives