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] Handle more cases for toSorted (and the likes) #2210

Open
boris-petrov opened this issue Oct 29, 2023 · 4 comments
Open

Comments

@boris-petrov
Copy link

boris-petrov commented Oct 29, 2023

no-useless-spread already handles cases like [...foo.toSorted()] which is awesome! However, it would be nice to also handle [...foo].toSorted() and [...foo].sort(), both of which can be replaced with foo.toSorted().

cc @fisker, @sindresorhus

P.S. Similar work was done in this PR.

@fisker
Copy link
Collaborator

fisker commented Oct 29, 2023

[...foo].toSorted()

is not safe to fix, since foo can be other types like string, Set..

Or even can't be reported.

@fisker
Copy link
Collaborator

fisker commented Oct 29, 2023

[...foo].sort()

Should definitely go into a new rule like prefer-array-to-sorted.

@abrahamguo
Copy link
Contributor

Wouldn't this suffer from the same problem — foo could still be a string, Set, etc. — and so [...foo].sort() cannot be reported either?

@fisker
Copy link
Collaborator

fisker commented Nov 30, 2023

I think it's reasonable to make a generic rule just to forbid .sort() except expression statements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants