-
-
Notifications
You must be signed in to change notification settings - Fork 362
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
Rule proposal: no-unnecessary-splice
#2359
Comments
This comment was marked as outdated.
This comment was marked as outdated.
Failarray.splice(index, 1, newValue); Passarray[index] = newValue; array = array.with(index, newValue); |
@fisker good one, but I'd prefer to have that configurable, as it depends on the targeted ECMA version if EDIT: actually, this doesn't look like that good of a replacement. Will leave this one for the end |
One thing to watch out for is whether Another thing is for all calls like |
Accepted |
#2361 is WIP, will try finishing it in the coming week. |
Hello, I'm curious if there is any progress on this proposal? |
Description
Saw
splice
being used instead ofpush
/pop
/shift
/unshift
in some projects. AFAIK it brings no performance gain and is harder to read/understand than the latter ones.Basically bans:
array.splice(index, 0)
(can be removed as no-op)array.splice(0, 1)
(as substitutable byarray.shift()
)array.splice(0, 0, element)
(as substitutable byarray.unshift(element)
- for 1 or more elements)array.splice(array.length - 1, 1)
(as substitutable byarray.pop()
)array.splice(array.length, 0, element)
(as substitutable byarray.push(element)
- for 1 or more elements)Should be easy to implement auto-fixer for those replacements.
Fail
Pass
Proposed rule name
no-unnecessary-splice
Additional Info
Happy to work on this once accepted (already have a stub).
This would make #2165 not needed any more
The text was updated successfully, but these errors were encountered: