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-iterator-to-array #2567

Open
fisker opened this issue Feb 20, 2025 · 0 comments
Open

Rule proposal: prefer-iterator-to-array #2567

fisker opened this issue Feb 20, 2025 · 0 comments

Comments

@fisker
Copy link
Collaborator

fisker commented Feb 20, 2025

Description

Iterator#toArray() is more clear to me that coverts iterator to array than [...iterator], especially when iterator is a long expression.

Examples

// ❌
[...map.values()].map(value => value * 2)

// ✅
map.values().toArray().map(value => value * 2)
map.values().map(value => value * 2).toArray()

Proposed rule name

prefer-iterator-to-array

Additional Info

Full list of Iterators https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator#description

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

1 participant