sindresorhus/eslint-plugin-unicorn
`consistent-existence-index-check`: No rationale given for style
Geschlossen
#2.714 geöffnet am 06.08.2025
docsgood for beginnerhelp wanted
Repository-Metriken
- Stars
- (5.022 Sterne)
- PR-Merge-Metriken
- (Durchschn. Merge 1T 16h) (399 gemergte PRs in 30 T)
Beschreibung
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