sindresorhus/eslint-plugin-unicorn

Rule proposal: Have `prefer-spread` handle `for..of`

Closed

#1,713 opened on Feb 3, 2022

 (3 comments) (1 reaction) (0 assignees)JavaScript (468 forks)user submission
enhancementhelp wanted

Repository metrics

Stars
 (5,022 stars)
PR merge metrics
 (Avg merge 1d 16h) (399 merged PRs in 30d)

Description

Description

Often no-for-loop results in something that is a simple spread, which prefer-spread should handle

This works for both arrays and iterators.

Fail

const result = []
for (const element of array) {
  result.push(element)
}
const result = []
for (const [index, element] of array.entries()) {
  result[index] = element
}

Pass

const result = [...array]

Contributor guide