-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Bug in the Style/MapToHash
cop
#12429
Comments
This change will break the compatibility of autocorrection, so I'll close it. Please refer to #12431 (comment) as well |
I disagree. In this example, autocorrection results in different behavior. |
In my tests, the autocorrection made to the presented code appear to be compatible. Removing the safe navigation operator from autocorrected code actually creates incompatibility. |
Before autocorrection: 2.7.6 :002 > hsh = { foo: 1, bar: 2 }
=> {:foo=>1, :bar=>2}
2.7.6 :003 > hsh&.map { |k, v| [k.to_s, v.next] }.to_h
=> {"foo"=>2, "bar"=>3}
2.7.6 :004 > hsh = nil
=> nil
2.7.6 :005 > hsh&.map { |k, v| [k.to_s, v.next] }.to_h
=> {} After autocorrection: 2.7.6 :006 > hsh = { foo: 1, bar: 2 }
=> {:foo=>1, :bar=>2}
2.7.6 :007 > hsh&.to_h { |k, v| [k.to_s, v.next] }
=> {"foo"=>2, "bar"=>3}
2.7.6 :008 > hsh = nil
=> nil
2.7.6 :009 > hsh&.to_h { |k, v| [k.to_s, v.next] }
=> nil Expected behaviour: 2.7.6 :010 > hsh = { foo: 1, bar: 2 }
=> {:foo=>1, :bar=>2}
2.7.6 :011 > hsh.to_h { |k, v| [k.to_s, v.next] }
=> {"foo"=>2, "bar"=>3}
2.7.6 :012 > hsh = nil
=> nil
2.7.6 :013 > hsh.to_h { |k, v| [k.to_s, v.next] }
=> {} |
Ah, understand. I will work on this again. Thank you! |
Fixes rubocop#12429. This PR fixes incorrect autocorrect for `Style/MapToHash` when using dot method calls for `to_h`.
…o_hash [Fix #12429] Fix incorrect autocorrect for `Style/MapToHash`
Actual behavior
I have the following code:
I run rubocop with autocorrection and get:
Expected behavior
RuboCop version
The text was updated successfully, but these errors were encountered: