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

Incorrect recommendation suggested by Performance/ChainArrayAllocation Cop #185

Closed
ashmaroli opened this issue Oct 26, 2020 · 1 comment · Fixed by #196
Closed

Incorrect recommendation suggested by Performance/ChainArrayAllocation Cop #185

ashmaroli opened this issue Oct 26, 2020 · 1 comment · Fixed by #196
Labels
bug Something isn't working

Comments

@ashmaroli
Copy link

Expected behavior

Expected RuboCop to suggest valid corrections.

Actual behavior

C: Performance/ChainArrayAllocation: Use unchained values_at! and compact! (followed by return array if required)
instead of chaining values_at...compact.

options.values_at("alpha", "beta", "gamma").compact.length > 1
                                           ^^^^^^^^

Problem

Hash instances do not respond to :values_at!

Steps to reproduce the problem

Run RuboCop against the following code:

def foo?(options = {})
  options.values_at("alpha", "beta", "gamma").compact.length > 1
end
@ashmaroli
Copy link
Author

Thanks for resolving this issue @fatkodima.
I have not manually tested the patch but will in a couple of days if a new version doesn't get shipped by then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants