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

prefer-array-some should also check for misuse of Array.findIndex() #1870

Closed
KurtPreston opened this issue Jul 27, 2022 · 2 comments · Fixed by #2370
Closed

prefer-array-some should also check for misuse of Array.findIndex() #1870

KurtPreston opened this issue Jul 27, 2022 · 2 comments · Fixed by #2370

Comments

@KurtPreston
Copy link

Description

prefer-array-some checks for situations in which Array.filter(...).length > 0 and Array.find(...) != null could be better written as Array.some(...)

It would be useful to also check for a similar suboptimal pattern: Array.findIndex(...) > -1

Example:

myArray.findIndex(someCondition) > -1

is equivalent to

myArray.some(someCondition)

Fail

[1, 2, 3].findIndex((i) => i % 2) > -1

Pass

[1, 2, 3].some((i) => i % 2)

Additional Info

No response

@KurtPreston KurtPreston changed the title Rule proposal: prefer-array-some should also check for misuse of Array.findIndex() Rule proposal: prefer-array-some should also check for misuse of Array.findIndex() Jul 27, 2022
@sindresorhus sindresorhus changed the title Rule proposal: prefer-array-some should also check for misuse of Array.findIndex() prefer-array-some should also check for misuse of Array.findIndex() Sep 12, 2022
@sindresorhus
Copy link
Owner

Accepted

@fisker
Copy link
Collaborator

fisker commented Sep 17, 2022

Should also check .findLastIndex() > -1 .

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

Successfully merging a pull request may close this issue.

3 participants