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

Improve suggesting Performance/RedundantMerge #334

Open
wscourge opened this issue Jan 23, 2023 · 0 comments
Open

Improve suggesting Performance/RedundantMerge #334

wscourge opened this issue Jan 23, 2023 · 0 comments

Comments

@wscourge
Copy link

Is your feature request related to a problem? Please describe.

Performance/RedundantMerge, that's unsafe-autocorrectable, suggests that I should:

Use accumulator[:low] = true instead of accumulator.merge!(low => true).

on the code below:

[{ a: 1 }, { a: 2 }, { a: 3 }].reduce({}).each do |accumulator, current|
  next accumulator.merge!(low: true) if current[:a] <= 2

  accumulator.merge!(low: false)
end

Assignment (.=) returns the assigned value, .merge! returns product hash, and the code would stop working.

Describe the solution you'd like

I'd like it to be smart enough not to suggest that, so I don't have to ignore it.

Describe alternatives you've considered

rubocop:disable Performance/RedundantMerge

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

No branches or pull requests

1 participant