Skip to content

Latest commit

 

History

History
53 lines (34 loc) · 1.04 KB

prefer-spread.md

File metadata and controls

53 lines (34 loc) · 1.04 KB

Prefer the spread operator over Array.from(…), Array#concat(…) and Array#slice()

Enforces the use of the spread operator (...) over

  • Array.from(…)

    Convert Iterable to Array.

    This rule adds on to the built-in prefer-spread rule, which only flags uses of .apply(). Does not enforce for TypedArray.from().

  • Array#concat(…)

    Concat an Array with one or more Array's or Array elements.

  • Array#slice()

    Shallow copy an Array.

    Variables named arrayBuffer, blob, buffer, file, and this are ignored.

This rule is partly fixable.

Fail

Array.from(set).map(element => foo(element));
const array = array1.concat(array2);
const copy = array.slice();

Pass

[...set].map(element => foo(element));
const array = [...array1, ...array2];
const tail = array.slice(1);
const copy = [...array];