prefer-spread
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"prefer-spread": "error",
},
},
];foo.apply(undefined, args);
foo.apply(null, args);
obj.foo.apply(obj, args);// Using spread syntax
foo(...args);
obj.foo(...args);
// The `this` binding is different.
foo.apply(obj, args);
obj.foo.apply(null, args);
obj.foo.apply(otherObj, args);
// The argument list is not variadic.
// Those are warned by the `no-useless-call` rule.
foo.apply(undefined, [1, 2, 3]);
foo.apply(null, [1, 2, 3]);
obj.foo.apply(obj, [1, 2, 3]);Examples from the ESLint documentation.
prefer-spread
eslint
export default [
{
rules: {
"prefer-spread": "error",
},
},
];prefer-spread
eslint plugin · style
{
"rules": {
"prefer-spread": "error"
}
}style/useSpreadOverApply
style · since 2.3.6
{
"linter": {
"rules": {
"style": {
"useSpreadOverApply": "error"
}
}
}
}Prefer the spread operator over Array.from(…), Array#concat(…), Array#{slice,toSpliced}(), and trivial for…of copies.
Disallow the use of undeclared variables unless mentioned in /*global */ comments
Disallow confusing multiline expressions
Disallow losing originally caught error when re-throwing custom errors