sonarjs/strings-comparison
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/strings-comparison": "error",
},
},
];Comparison operators should not be used with strings
var appleNumber = "123";
var orangeNumber = "45";
if (appleNumber < orangeNumber) { // Noncompliant, this condition is true
alert("There are more oranges");
}var appleNumber = "123";
var orangeNumber = "45";
if (Number(appleNumber) < Number(orangeNumber)) {
alert("There are more oranges");
}Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
sonarjs/strings-comparison
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/strings-comparison": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Shorthand object properties should be grouped at the beginning or end of an object declaration
Loops should not contain more than a single "break" or "continue" statement
Regular expressions using Unicode character classes or property escapes should enable the unicode flag
Local variables should not be declared and then immediately returned or thrown
Values not convertible to numbers should not be used in numeric comparisons