prefer-object-spread
eslint
Safe autofix
eslint.config.js
export default [
{
rules: {
"prefer-object-spread": "error",
},
},
];Disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead
Object.assign({}, foo);
Object.assign({}, {foo: 'bar'});
Object.assign({ foo: 'bar'}, baz);
Object.assign({}, baz, { foo: 'bar' });
Object.assign({}, { ...baz });
// Object.assign with a single argument that is an object literal
Object.assign({});
Object.assign({ foo: bar });({ ...foo });
({ ...baz, foo: 'bar' });
// Any Object.assign call without an object literal as the first argument
Object.assign(foo, { bar: baz });
Object.assign(foo, bar);
Object.assign(foo, { bar, baz });
Object.assign(foo, { ...baz });Examples from the ESLint documentation.
prefer-object-spread
eslint
export default [
{
rules: {
"prefer-object-spread": "error",
},
},
];prefer-object-spread
eslint plugin · style
{
"rules": {
"prefer-object-spread": "error"
}
}style/useObjectSpread
style · since 2.0.0
{
"linter": {
"rules": {
"style": {
"useObjectSpread": "error"
}
}
}
}Require grouped accessor pairs in object literals and classes
Disallow returning values from Promise executor functions
Require braces around arrow function bodies
Disallow if statements as the only statement in else blocks
Disallow use of chained assignment expressions