From 6db2055a039ac85e054859400c80f1ee79f9e703 Mon Sep 17 00:00:00 2001 From: Kevin Partington Date: Mon, 28 May 2018 11:28:29 -0500 Subject: [PATCH] Fix: Add prefer-object-spread to main rules directory This fixes a broken link in docs/rules index. Root cause is eslint/eslint-release#22 --- docs/rules/prefer-object-spread.md | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 docs/rules/prefer-object-spread.md diff --git a/docs/rules/prefer-object-spread.md b/docs/rules/prefer-object-spread.md new file mode 100644 index 0000000000..1473578da6 --- /dev/null +++ b/docs/rules/prefer-object-spread.md @@ -0,0 +1,65 @@ +--- +title: prefer-object-spread - Rules +layout: doc +edit_link: https://github.com/eslint/eslint/edit/master/docs/rules/prefer-object-spread.md +--- + + +# Prefer use of an object spread over `Object.assign` (prefer-object-spread) + +(fixable) The `--fix` option on the [command line](../user-guide/command-line-interface#fix) can automatically fix some of the problems reported by this rule. + +When Object.assign is called using an object literal as the first argument, this rule requires using the object spread syntax instead. This rule also warns on cases where an `Object.assign` call is made using a single argument that is an object literal, in this case, the `Object.assign` call is not needed. + +## Rule Details + +Examples of **incorrect** code for this rule: + +```js + +Object.assign({}, foo) + +Object.assign({}, {foo: 'bar'}) + +Object.assign({ foo: 'bar'}, baz) + +Object.assign({ foo: 'bar' }, Object.assign({ bar: 'foo' })) + +Object.assign({}, { foo, bar, baz }) + +Object.assign({}, { ...baz }) + +// Object.assign with a single argument that is an object literal +Object.assign({}); + +Object.assign({ foo: bar }); +``` + +Examples of **correct** code for this rule: + +```js + +Object.assign(...foo); + +// Any Object.assign call without an object literal as the first argument +Object.assign(foo, { bar: baz }); + +Object.assign(foo, Object.assign(bar)); + +Object.assign(foo, { bar, baz }) + +Object.assign(foo, { ...baz }); +``` + +## When Not To Use It + +When you don't care about syntactic sugar added by the object spread property. + +## Version + +This rule was introduced in ESLint 5.0.0-alpha.3. + +## Resources + +* [Rule source](https://github.com/eslint/eslint/tree/master/lib/rules/prefer-object-spread.js) +* [Documentation source](https://github.com/eslint/eslint/tree/master/docs/rules/prefer-object-spread.md)