Skip to content

unicorn/consistent-existence-index-check Style

🛠️ An auto-fix is available for this rule.

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) {
}

References

Released under the MIT License.