sindresorhus/eslint-plugin-unicorn
Rule proposal: Have `prefer-spread` handle `for..of`
Closed
#1,713 opened on Feb 3, 2022
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]