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

Style/HashTransformKeys with to_h with a block is too greedy now #8630

Closed
zverok opened this issue Sep 1, 2020 · 2 comments
Closed

Style/HashTransformKeys with to_h with a block is too greedy now #8630

zverok opened this issue Sep 1, 2020 · 2 comments

Comments

@zverok
Copy link
Contributor

zverok commented Sep 1, 2020

This code (and any like this, using Array#to_h or Enumerable#to_h) is a false positive now:

%i[a b c].zip([1, 2, 3]).to_h { |name, val| [name, val**2] }

C: Style/HashTransformValues: Prefer transform_values over to_h {...}.
%i[a b c].zip([1, 2, 3]).to_h { |name, val| [name, val**2] }
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

(After #8517 probably)

@marcandre
Copy link
Contributor

cc/ @eugeneius

@eugeneius
Copy link
Contributor

This was already a problem for code using map { ... }.to_h before #8517:

$ rubocop _0.89.0_ --only Style/HashTransformValues --stdin foo.rb <<< "%i[a b c].zip([1, 2, 3]).map { |name, val| [name, val**2] }.to_h"
Inspecting 1 file
C

Offenses:

foo.rb:1:1: C: Style/HashTransformValues: Prefer transform_values over map {...}.to_h.
%i[a b c].zip([1, 2, 3]).map { |name, val| [name, val**2] }.to_h
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected

Anyway, I opened #8648 with a fix.

@koic koic closed this as completed in f641f6e Sep 9, 2020
koic added a commit that referenced this issue Sep 9, 2020
…itives

[Fix #8630] Fix some hash transformation false positives
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants