unicorn/consistent-existence-index-check Style
What it does
Enforce consistent style for element existence checks with indexOf()
, lastIndexOf()
, findIndex()
, and findLastIndex()
Why is this bad?
This rule is only meant to enforce a specific style and make comparisons more clear.
Examples
Examples of incorrect code for this rule:
javascript
const index = foo.indexOf("bar");
if (index < 0) {
}
javascript
const index = foo.indexOf("bar");
if (index >= 0) {
}
Examples of correct code for this rule:
javascript
const index = foo.indexOf("bar");
if (index === -1) {
}
javascript
const index = foo.indexOf("bar");
if (index !== -1) {
}