sindresorhus/eslint-plugin-unicorn

`consistent-existence-index-check`: No rationale given for style

Fermée

#2 714 ouverte le 6 août 2025

 (1 commentaire) (0 réaction) (0 personne assignée)JavaScript (468 forks)user submission
docsgood for beginnerhelp wanted

Métriques du dépôt

Stars
 (5 022 étoiles)
Métriques de merge PR
 (Merge moyen 4h 30m) (26 PRs mergées en 30 j)

Description

Description

This rule was introduced: https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1024, and our codebase uses the style: >= 0 and < 0 rather than !== -1 or === -1. Why this is preferred should either be documented, or a alternative style option could be provided.

Examples

This potential option would invert the typical behavior of the rule.

const index = foo.indexOf('bar');

// ❌
if (index === -1) {}


// ✅
if (index < 0) {}
const index = foo.indexOf('bar');

// ❌
if (index !== -1) {}

// ✅
if (index >= 0) {}

Additional Info

No response

Guide contributeur