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/BracesAroundHashParameters auto correction can remove keys #6510

Closed
DMA57361 opened this issue Nov 21, 2018 · 1 comment
Closed

Style/BracesAroundHashParameters auto correction can remove keys #6510

DMA57361 opened this issue Nov 21, 2018 · 1 comment
Labels

Comments

@DMA57361
Copy link

I'm running corrections over some older code that hasn't been looked after by Rubocop before, and I've just had the Style/BracesAroundHashParameters cop auto-correct a hash that was laid out in a pretty ugly way and it has unexpectedly removed the last key.

The hash affected was effectively

  HashWithIndifferentAccess.new(
    {'key1' => 1,
     'key2' => 2}
  )

Expected behavior

Remove the braces and correct indentation.

Actual behavior

In additional to the expected behaviour, 'key2' => 2 was entirely removed.

Steps to reproduce the problem

Given this contrived eg.rb file:

def make_a_hash
  HashWithIndifferentAccess.new(
    {'key1' => 1,
     'key2' => 2}
  )
end

Run Rubocop corrections:

$ bundle exec rubocop --safe-auto-correct eg.rb
Inspecting 1 file
C

Offenses:

eg.rb:3:5: C: [Corrected] Style/BracesAroundHashParameters: Redundant curly braces around a hash parameter.
    {'key1' => 1, ...
    ^^^^^^^^^^^^^
eg.rb:3:16: C: [Corrected] Style/TrailingCommaInArguments: Avoid comma after the last parameter of a method call.
    'key1' => 1,
               ^

1 file inspected, 2 offenses detected, 2 offenses corrected

The eg.rb file is left in this state:

def make_a_hash
  HashWithIndifferentAccess.new(
    'key1' => 1
  )
end

RuboCop version

$ bundle exec rubocop -V
0.60.0 (using Parser 2.5.3.0, running on ruby 2.3.7 x86_64-darwin18)
@Drenmi Drenmi added the bug label Nov 22, 2018
@koic
Copy link
Member

koic commented Nov 23, 2018

Thanks for the feedback. This issue has been fixed by #6443. It will be resolved in the next release of RuboCop (> 0.60.0) .

@koic koic closed this as completed Nov 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants