sonarjs/no-identical-functions
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/no-identical-functions": "error",
},
},
];function calculateCode() {
doTheThing();
doOtherThing();
return code;
}
function getName() { // Noncompliant
doTheThing();
doOtherThing();
return code;
}function calculateCode() {
doTheThing();
doOtherThing();
return code;
}
function getName() {
return calculateCode();
}Examples from the ESLint documentation.
sonarjs/no-identical-functions
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/no-identical-functions": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Identical expressions should not be used on both sides of a binary operator
"if/else if" chains and "switch" cases should not have the same condition
Return values from functions without side effects should not be ignored
React's useState hook should not be used directly in the render function or body of a component