💼 This rule is enabled in the ✅ recommended
config.
🔧 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
constructorWeakMap
constructorSet
constructorWeakSet
constructorTypedArray
constructorArray.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.
const array = [firstElement, ...[secondElement], thirdElement];
const object = {firstProperty, ...{secondProperty}, thirdProperty};
foo(firstArgument, ...[secondArgument], thirdArgument);
const object = new Foo(firstArgument, ...[secondArgument], thirdArgument);
const set = new Set([...iterable]);
const results = await Promise.all([...iterable]);
for (const foo of [...set]);
function * foo() {
yield * [...anotherGenerator()];
}
function foo(bar) {
return [
...bar.map(x => x * 2),
];
}
const array = [firstElement, secondElement, thirdElement];
const object = {firstProperty, secondProperty, thirdProperty};
foo(firstArgument, secondArgument, thirdArgument);
const object = new Foo(firstArgument, secondArgument, thirdArgument);
const array = [...foo, bar];
const object = {...foo, bar};
foo(foo, ...bar);
const object = new Foo(...foo, bar);
const set = new Set(iterable);
const results = await Promise.all(iterable);
for (const foo of set);
function * foo() {
yield * anotherGenerator();
}
function foo(bar) {
return bar.map(x => x * 2);
}