no-useless-spread

March 27, 2026 Β· View on GitHub

πŸ“ Disallow unnecessary spread.

πŸ’Ό This rule is enabled in the following configs: βœ… recommended, β˜‘οΈ unopinionated.

πŸ”§ This rule is automatically fixable by the --fix CLI option.

  • Using spread syntax in the following cases is unnecessary:

    • Spread an array literal as elements of an array literal
    • Spread an array literal as arguments of a call or a new call
    • Spread an object literal as properties of an object literal
    • Use spread syntax to clone an array created inline
  • The following builtins accept an iterable, so it's unnecessary to convert the iterable to an array:

    • Map constructor
    • WeakMap constructor
    • Set constructor
    • WeakSet constructor
    • TypedArray constructor
    • Array.from(…)
    • TypedArray.from(…)
    • Promise.{all,allSettled,any,race}(…)
    • Object.fromEntries(…)
  • for…of loop can iterate over any iterable object not just array, so it's unnecessary to convert the iterable to an array.

  • yield* can delegate to another iterable, so it's unnecessary to convert the iterable to an array.

Examples

// ❌
const array = [firstElement, ...[secondElement], thirdElement];

// βœ…
const array = [firstElement, secondElement, thirdElement];
// ❌
const object = {firstProperty, ...{secondProperty}, thirdProperty};

// βœ…
const object = {firstProperty, secondProperty, thirdProperty};
// ❌
foo(firstArgument, ...[secondArgument], thirdArgument);

// βœ…
foo(firstArgument, secondArgument, thirdArgument);
// ❌
const object = new Foo(firstArgument, ...[secondArgument], thirdArgument);

// βœ…
const object = new Foo(firstArgument, secondArgument, thirdArgument);
// ❌
const set = new Set([...iterable]);

// βœ…
const set = new Set(iterable);
// ❌
const results = await Promise.all([...iterable]);

// βœ…
const results = await Promise.all(iterable);
// ❌
for (const foo of [...set]);

// βœ…
for (const foo of set);
// ❌
function * foo() {
	yield * [...anotherGenerator()];
}

// βœ…
function * foo() {
	yield * anotherGenerator();
}
// βœ…
const array = [...foo, bar];
// βœ…
const object = {...foo, bar};
// βœ…
foo(foo, ...bar);
// βœ…
const object = new Foo(...foo, bar);