sonarjs/index-of-compare-to-positive-number
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/index-of-compare-to-positive-number": "error",
},
},
];"indexOf" checks should not be for positive numbers
var color = "blue";
var name = "ishmael";
var arr = [color, name];
if (arr.indexOf("blue") > 0) { // Noncompliant
// ...
}var color = "blue";
var name = "ishmael";
var arr = [color, name];
if (arr.indexOf("blue") >= 0) {
// ...
}
if (arr.includes("blue")) {
// ...
}Examples from the ESLint documentation.
sonarjs/index-of-compare-to-positive-number
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/index-of-compare-to-positive-number": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Functions should be called consistently with or without "new"
"in" should not be used with primitive types
JWT should be signed and verified with strong cipher algorithms
Lifecycle hooks should not be interleaved with test cases or nested suites
Assertion arguments should be passed in the correct order