sonarjs/no-element-overwrite
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/no-element-overwrite": "error",
},
},
];Collection elements should not be replaced unconditionally
fruits[1] = "banana";
fruits[1] = "apple"; // Noncompliant - value on index 1 is overwritten
myMap.set("key", 1);
myMap.set("key", 2); // Noncompliant - value for key "key" is replaced
mySet.add(1);
mySet.add(1); // Noncompliant - element is already in the setThe documentation shows no correct example for this rule.
Examples from the ESLint documentation.
sonarjs/no-element-overwrite
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/no-element-overwrite": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Two branches in a conditional structure should not have exactly the same implementation
Reluctant quantifiers in regular expressions should be followed by an expression that can't match the empty string
Test titles should be unique within the same suite
Alternation in regular expressions should not contain empty alternatives
Parameterized tests should not contain duplicate test cases
Empty character classes should not be used