sindresorhus/eslint-plugin-unicorn

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

Chiusa

#2714 aperta il 6 ago 2025

 (1 commento) (0 reazioni) (0 assegnatari)JavaScript (468 fork)user submission
docsgood for beginnerhelp wanted

Metriche repository

Star
 (5022 stelle)
Metriche merge PR
 (Merge medio 1g 16h) (399 PR mergiate in 30 g)

Descrizione

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

Guida contributor