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

no-useless-spread: Check more cases #1482

Closed
fisker opened this issue Aug 13, 2021 · 4 comments · Fixed by #1980
Closed

no-useless-spread: Check more cases #1482

fisker opened this issue Aug 13, 2021 · 4 comments · Fixed by #1980
Assignees
Labels
💵 Funded on Issuehunt This issue has been funded on Issuehunt enhancement

Comments

@fisker
Copy link
Collaborator

fisker commented Aug 13, 2021

Issuehunt badges

(The badge links to a different issue but the bounty applies to this issue)

Fail

const array = [
	...foo.map(/* ... */)
];

Other array methods returns a new array, eg: concat(), flatMap(), copyWithin(), etc
Other known arrays, eg: Array.from(), Object.keys(), ...

Pass

const array = foo.map(/* ... */);

These cases are like "useless array copy"

@fisker fisker changed the title no-useless-spread check more cases no-useless-spread: Check more cases Aug 13, 2021
@rightaway
Copy link

It can check that spread isn't used when there's only a single property. So { ...expression } and [ ...expression ] should both just be expression.

@fisker
Copy link
Collaborator Author

fisker commented May 13, 2022

It can check that spread isn't used when there's only a single property.

It can be making a shallow copy. In object spread, it can also ensuring object type.

function foo(options) {
	const {bar} = {...options};
}

@rightaway
Copy link

Could checking this be added as an option? Sometimes spread is used just to combine things, so if you start off with { ...a, b: null, c: null } and then later remove b and c you're left with { ...a } when you really could replace it with a.

If there was this option you could disable the rule in cases when you want a shallow object.

@sindresorhus sindresorhus added the 💵 Funded on Issuehunt This issue has been funded on Issuehunt label Nov 18, 2022
@fisker fisker self-assigned this Nov 19, 2022
@fisker
Copy link
Collaborator Author

fisker commented Nov 19, 2022

@rightaway
I'm going to skip check spreading single UNKNOWN object, if you still want it please open a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💵 Funded on Issuehunt This issue has been funded on Issuehunt enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants