sindresorhus/eslint-plugin-unicorn

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

Open

#2,714 建立於 2025年8月6日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)JavaScript (5,022 star) (468 fork)user submission
docsgood for beginnerhelp wanted

描述

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

貢獻者指南