rubocop / rubocop-performance

An extension of RuboCop focused on code performance checks.
https://docs.rubocop.org/rubocop-performance
MIT License
670 stars 79 forks source link

Add new `ArrayPushSingle` cop to replace `a.push(x)` with `a << x` #433

Open amomchilov opened 8 months ago

amomchilov commented 8 months ago

Closes #431


Before submitting the PR make sure the following are checked:

ydakuka commented 8 months ago

Is this related to https://github.com/rubocop/rubocop/issues/12053 ?

amomchilov commented 8 months ago

@ydakuka I hadn't seen that, but I guess it's pretty similar!

I think two separate cops would be good here. One to turn a.push(x) into a << x, and another to take a series of a << xs (or pushes) and turn them into one.