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: Prefer array last methods over reverse #2417

Open
fregante opened this issue Jul 31, 2024 · 5 comments
Open

Rule proposal: Prefer array last methods over reverse #2417

fregante opened this issue Jul 31, 2024 · 5 comments

Comments

@fregante
Copy link
Collaborator

fregante commented Jul 31, 2024

Description

It was mentioned in #1323 but it was closed in favor of prefer-array-find, which only covered filter instead.

Fail

array.reverse().find(logic);
array.reverse().findIndex(logic);
array.reverse().indexOf(logic);
array.reverse().reduce(logic);
array.toReversed().find(logic);
array.toReversed().findIndex(logic);
array.toReversed().indexOf(logic);
array.toReversed().reduce(logic);

Pass

array.findLast(logic);
array.findLastIndex(logic);
array.lastIndexOf(logic);
array.reduceRight(logic);

Proposed rule name

avoid-array-reverse

Additional Info

No response

@sindresorhus
Copy link
Owner

Name: prefer-array-last-methods?

@sindresorhus
Copy link
Owner

Accepted.

@fisker
Copy link
Collaborator

fisker commented Aug 21, 2024

array.toReversed().find(logic);
array.toReversed().findIndex(logic);
array.toReversed().indexOf(logic);
array.toReversed().reduce(logic);

@axetroy
Copy link
Contributor

axetroy commented Aug 22, 2024

array.toReversed().find(logic);
array.toReversed().findIndex(logic);
array.toReversed().indexOf(logic);
array.toReversed().reduce(logic);

Before node 18.x is deprecated, the current solution is more suitable #2428 (comment)

@fregante
Copy link
Collaborator Author

@fisker I now added them to the "fail" examples above

@fregante fregante changed the title Rule proposal: Prefer array last methods over reverse Rule proposal: Prefer array last methods over reverse Sep 3, 2024
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

4 participants