sindresorhus/eslint-plugin-unicorn

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

Fechada

#2.714 aberto em 6 de ago. de 2025

 (1 comentário) (0 reação) (0 responsável)JavaScript (468 forks)user submission
docsgood for beginnerhelp wanted

Métricas do repositório

Stars
 (5.022 estrelas)
Métricas de merge de PR
 (Mesclagem média 1d 16h) (399 fundiu PRs em 30d)

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

Guia do colaborador