sindresorhus/eslint-plugin-unicorn

Rule proposal: Enforce `.toArray()` at the end of `Iterator` methods chain

Fechada

#2.767 aberto em 25 de set. de 2025

 (5 comentários) (1 reação) (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

Note that it's a good idea to call toArray() as a last step of your processing. For example, fibonacci().take(10).toArray().filter(...) is less efficient, because iterator helpers are lazy and avoids creating a temporary array.

From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/toArray

Examples

// ❌
foo.toArray().filter(...)
//            ^^^^^^ Array#filter()

// ✅
foo.filter(...).toArray()
//  ^^^^^^ Iterator#filter()

Proposed rule name

not sure

Additional Info

No response

Guia do colaborador