sonarjs/no-identical-expressions
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/no-identical-expressions": "error",
},
},
];Identical expressions should not be used on both sides of a binary operator
if (a == b && a == b) { // if the first one is true, the second one is too
doX();
}
if (a > a) { // always false
doW();
}
var j = 5 / 5; //always 1
var k = 5 - 5; //always 0The documentation shows no correct example for this rule.
Examples from the ESLint documentation.
sonarjs/no-identical-expressions
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/no-identical-expressions": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
"if/else if" chains and "switch" cases should not have the same condition
Functions should not have identical implementations
React's useState hook should not be used directly in the render function or body of a component
Return values from functions without side effects should not be ignored