sindresorhus/eslint-plugin-unicorn

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

クローズ

#2,714 opened on 2025/08/06

 (1 件のコメント) (0 件のリアクション) (0 人の担当者)JavaScript (468 件のフォーク)user submission
docsgood for beginnerhelp wanted

Repository metrics

Stars
 (5,022 個のスター)
PR merge metrics
 (平均マージ 4h 30m) (30d で 26 merged PRs)

説明

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

コントリビューターガイド