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
newcall - 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:
MapconstructorWeakMapconstructorSetconstructorWeakSetconstructorTypedArrayconstructorArray.from(β¦)TypedArray.from(β¦)Promise.{all,allSettled,any,race}(β¦)Object.fromEntries(β¦)
-
forβ¦ofloop 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);