Rule request: `prefer-object-spread`
See original GitHub issuePlease describe what the rule should do:
When it finds an Object.assign
call where the first argument is an object literal, the rule should error, and recommend using the object spread operator instead.
What category of rule is this? (place an “X” next to just one item)
[ ] Enforces code style [ ] Warns about a potential error [x] Suggests an alternate way of doing something [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
return Object.assign({}, foo, { bar: baz }, quux); // should be `return { ...foo, bar: baz, ...quux };`
return Object.assign({ foo }, bar, { baz }); // should be `return { foo, ...bar, baz };`
return Object.assign(foo, bar, { baz }); // should not warn
Why should this rule be included in ESLint (instead of a plugin)? Just like http://eslint.org/docs/rules/prefer-spread, this recommends that users use a syntax feature (an operator) instead of API (Object.assign) for the cases where it makes sense. Both are core language features, and eslint core should be where core language feature rules live.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:12
- Comments:32 (31 by maintainers)
@mysticatea we already have an implementation of this rule internally at @airbnb, mind if we submit a PR?
I’ll champion this proposal, new
prefer-object-spread
rule. The advisory rule for new syntax would be helpful. TSLint looks to have the rule.