-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Description
Please 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.