You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It isn't included, but it would also complain for this code: {a: 1, b: 2}.to_h { |k, _unused_v| [k, k] }
Notice: value of the hash is not used at all. It's just using key
There are two issues with that:
It shouldn't complain when value is not used at all (as it recommends to use transform_values, which in that case is not possible to be used)
Autocorrects to code with NameError: undefined local variable or method 'k' for main:Object
Example code in "Steps to reproduce" section
Expected behavior
Two possible fixes:
Shouldn't detect HashTransformValues rule when .to_h { |k, v| ... } is not using value v.
Shouldn't autofix (-A) to code with NameError (don't correct it for the user, let user fix the issue themselves?)
Actual behavior
Detects offence and autofixes to code which raises NameError.
…` and `Style/HashTransformValues`
Fixesrubocop#10927.
This PR fixes a false positive for `Style/HashTransformKeys` and `Style/HashTransformValues`
when not using transformed block argument.
…Style/HashTransformValues`
Fixes#10927.
This PR fixes a false positive for `Style/HashTransformKeys` and `Style/HashTransformValues`
when not using transformed block argument.
Current docs for HashTransformValues mentions that
It isn't included, but it would also complain for this code:
{a: 1, b: 2}.to_h { |k, _unused_v| [k, k] }
Notice: value of the hash is not used at all. It's just using key
There are two issues with that:
transform_values
, which in that case is not possible to be used)NameError: undefined local variable or method 'k' for main:Object
Example code in "Steps to reproduce" section
Expected behavior
Two possible fixes:
HashTransformValues
rule when.to_h { |k, v| ... }
is not using valuev
.-A
) to code withNameError
(don't correct it for the user, let user fix the issue themselves?)Actual behavior
Detects offence and autofixes to code which raises NameError.
Steps to reproduce the problem
RuboCop version
The text was updated successfully, but these errors were encountered: