unicorn/no-useless-spread
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-useless-spread": "error",
},
},
];const array = [firstElement, ...[secondElement], thirdElement];const object = {firstProperty, ...{secondProperty}, thirdProperty};foo(firstArgument, ...[secondArgument], thirdArgument);const array = [firstElement, secondElement, thirdElement];const object = {firstProperty, secondProperty, thirdProperty};foo(firstArgument, secondArgument, thirdArgument);Examples from the ESLint documentation.
unicorn/no-useless-spread
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-useless-spread": "error",
},
},
];unicorn/no-useless-spread
unicorn plugin · correctness
{
"rules": {
"unicorn/no-useless-spread": "error"
}
}nursery/noUselessSpread
nursery · since 2.6.7
{
"linter": {
"rules": {
"nursery": {
"noUselessSpread": "error"
}
}
}
}Disallow useless array length check.
Prefer using Set#size instead of Array#length.
Disallow useless fallback when spreading in object literals.
Disallow passing single-element arrays to Promise methods.
Prevent calling EventTarget#removeEventListener() with the result of an expression.