sindresorhus/eslint-plugin-unicorn

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

Fechada

#2.567 aberto em 20 de fev. de 2025

 (2 comentários) (3 reações) (0 responsável)JavaScript (468 forks)user submission
help wantednew rule

Métricas do repositório

Stars
 (5.022 estrelas)
Métricas de merge de PR
 (Mesclagem média 4h 30m) (26 fundiu PRs em 30d)

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

Guia do colaborador