Skip to content

Latest commit

 

History

History
51 lines (33 loc) · 980 Bytes

File metadata and controls

51 lines (33 loc) · 980 Bytes

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.

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];