Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add more examples for prefer-object-spread #15831

Merged
merged 2 commits into from May 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 9 additions & 12 deletions docs/src/rules/prefer-object-spread.md
Expand Up @@ -20,17 +20,15 @@ Examples of **incorrect** code for this rule:
```js
/*eslint prefer-object-spread: "error"*/

Object.assign({}, foo)
Object.assign({}, foo);

Object.assign({}, {foo: 'bar'})
Object.assign({}, {foo: 'bar'});

Object.assign({ foo: 'bar'}, baz)
Object.assign({ foo: 'bar'}, baz);

Object.assign({ foo: 'bar' }, Object.assign({ bar: 'foo' }))
Object.assign({}, baz, { foo: 'bar' });

Object.assign({}, { foo, bar, baz })

Object.assign({}, { ...baz })
Object.assign({}, { ...baz });

// Object.assign with a single argument that is an object literal
Object.assign({});
Expand All @@ -43,14 +41,13 @@ Examples of **correct** code for this rule:
```js
/*eslint prefer-object-spread: "error"*/

Object.assign(...foo);
({ ...foo });

// Any Object.assign call without an object literal as the first argument
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep this comment somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Just updated.

Object.assign(foo, { bar: baz });
({ ...baz, foo: 'bar' });
coderaiser marked this conversation as resolved.
Show resolved Hide resolved

Object.assign(foo, Object.assign(bar));
Object.assign(foo, bar);

Object.assign(foo, { bar, baz })
Object.assign(foo, { bar, baz });

Object.assign(foo, { ...baz });
```
Expand Down