sonarjs/values-not-convertible-to-numbers
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/values-not-convertible-to-numbers": "error",
},
},
];Values not convertible to numbers should not be used in numeric comparisons
var x; // x is currently "undefined"
if (someCondition()) {
x = 42;
}
if (42 > x) { // Noncompliant; "x" might still be "undefined"
doSomething();
}
var obj = {prop: 42};
if (obj > 24) { // Noncompliant
doSomething();
}var x;
if (someCondition()) {
x = 42;
} else {
x = foo();
}
if (42 > x) {
doSomething();
}
var obj = {prop: 42};
if (obj.prop > 24) {
doSomething();
}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/values-not-convertible-to-numbers
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/values-not-convertible-to-numbers": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Variable, property and parameter names should comply with a naming convention
Regular expressions using Unicode character classes or property escapes should enable the unicode flag
Loops should not contain more than a single "break" or "continue" statement
Shorthand object properties should be grouped at the beginning or end of an object declaration