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

Rule Proposal: replace .filter()[0] with .find() #478

Closed
oscarmarcelo opened this issue May 15, 2020 · 1 comment
Closed

Rule Proposal: replace .filter()[0] with .find() #478

oscarmarcelo opened this issue May 15, 2020 · 1 comment

Comments

@oscarmarcelo
Copy link

Honestly, I'm not sure if I should add this here or in unicorn, but here it goes:

Rule Proposal

A rule to suggest replacing the use of .filter()[0] with .find(), since find breaks the loop as soon as it finds a match.

Fail

const item = array.filter(x => x === y)[0];

Pass

const item = array.find(x => x === y);

For the rule name, may I suggest something like no-filter-zero-index.

@sindresorhus
Copy link
Member

This needs to be opened on eslint-plugin-unicorn.

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

No branches or pull requests

2 participants