eslint-plugin-unicorn
eslint-plugin-unicorn copied to clipboard
[no-useless-spread] Handle more cases for `toSorted` (and the likes)
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.
[...foo].toSorted()
is not safe to fix, since foo
can be other types like string
, Set
..
Or even can't be reported.
[...foo].sort()
Should definitely go into a new rule like prefer-array-to-sorted
.
Wouldn't this suffer from the same problem — foo
could still be a string
, Set
, etc. — and so [...foo].sort()
cannot be reported either?
I think it's reasonable to make a generic rule just to forbid .sort()
except expression statements.