sindresorhus/eslint-plugin-unicorn

Rule proposal: `prefer-iterator-to-array`

Open

#2 567 ouverte le 20 févr. 2025

Voir sur GitHub
 (2 commentaires) (3 réactions) (0 assignés)JavaScript (5 022 stars) (468 forks)user submission
help wantednew rule

Description

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

Guide contributeur