Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consistent-existence-index-check add option greater-than and none-zero #2471

Open
ximex opened this issue Oct 7, 2024 · 3 comments
Open

Comments

@ximex
Copy link

ximex commented Oct 7, 2024

Description

I want to have the same option as explicit-length-check to choose between greater-than and none-zero.

none-zero could stay as default but if changed to greater-than it should behave as below

Fail

const index = foo.indexOf('bar');
if (index !== -1) {}

Pass

const index = foo.indexOf('bar');
if (index > -1) {}

Additional Info

https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/explicit-length-check.md#options

@ximex ximex changed the title consistent-existence-index-check: consistent-existence-index-check: add option greater-than and none-zero Oct 7, 2024
@fisker
Copy link
Collaborator

fisker commented Oct 8, 2024

Any reason you don't want === -1 and !== -1?

@ximex
Copy link
Author

ximex commented Oct 11, 2024

there is no hard reason. i know that it makes no different but it is more precise as value couldn't be below -1. and as the other rule has also the option i think this one could also get it

@fregante fregante changed the title consistent-existence-index-check: add option greater-than and none-zero 2470|prefer-array-flat awkward autofix on .concat().concat() Oct 20, 2024
@fregante fregante changed the title 2470|prefer-array-flat awkward autofix on .concat().concat() prefer-array-flat awkward autofix on .concat().concat() Oct 20, 2024
@fregante fregante changed the title prefer-array-flat awkward autofix on .concat().concat() consistent-existence-index-check: add option greater-than and none-zero Oct 20, 2024
@github-actions github-actions bot changed the title consistent-existence-index-check: add option greater-than and none-zero consistent-existence-index-check add option greater-than and none-zero Oct 20, 2024
@axetroy
Copy link
Contributor

axetroy commented Nov 22, 2024

Use -1 to make the style be kept consistent

Otherwise, someone would write code like this

index >= 0
index > -1
index < 0
index <= -1

This makes the code confusing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants