sonarjs/non-number-in-arithmetic-expression
eslint-plugin-sonarjs
No autofix
eslint.config.js
export default [
{
rules: {
"sonarjs/non-number-in-arithmetic-expression": "error",
},
},
];Arithmetic operators should only have numbers as operands
str = "80";
quarter = str / 4; // Noncompliant
if (str < 10) { // Noncompliant
// ...
}str = "80";
parsedStr = parseInt(str);
quarter = parsedStr / 4;
if (parsedStr < 10) {
// ...
}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/non-number-in-arithmetic-expression
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/non-number-in-arithmetic-expression": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Arithmetic operations should not result in "NaN"
Variables declared with "var" should be declared before they are used
Unused function parameters should be removed
Local variables should not be declared and then immediately returned or thrown