sindresorhus/eslint-plugin-unicorn

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

Chiusa

#2018 aperta il 19 dic 2022

 (6 commenti) (2 reazioni) (0 assegnatari)JavaScript (468 fork)user submission
bughelp wanted

Metriche repository

Star
 (5022 stelle)
Metriche merge PR
 (Merge medio 1g 16h) (399 PR mergiate in 30 g)

Descrizione

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>

Guida contributor