sindresorhus/eslint-plugin-unicorn

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

Open

#2,567 创建于 2025年2月20日

在 GitHub 查看
 (2 评论) (3 反应) (0 负责人)JavaScript (5,022 star) (468 fork)user submission
help wantednew rule

描述

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

贡献者指南