sindresorhus/eslint-plugin-unicorn

`no-useless-spread` False positive with iterator helpers

Closed

#2,018 opened on Dec 19, 2022

 (6 comments) (2 reactions) (0 assignees)JavaScript (468 forks)user submission
bughelp wanted

Repository metrics

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

Description

When using a polyfill for TC39 Iterator Helpers, trying to convert a generator produced by one of the helpers to an array via the spread operator, results in said spread operator being marked as useless.

Rule effected: unicorn/no-useless-spread

Example:

const data = new Map([["a", 1], ["b", 2], ["c", 3]]);
const foo = [...data.values().map((d) => d * 2)]; // [2, 4, 6]

is incorrectly flagged and fixed to:

const data = new Map([["a", 1], ["b", 2], ["c", 3]]);
const foo = data.values().map((d) => d * 2); // Generator<number, void, undefined>

Contributor guide