Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

autocorrect Performance/RedundantMerge breaks syntax #86

Closed
Tietew opened this issue Dec 11, 2019 · 0 comments · Fixed by #89
Closed

autocorrect Performance/RedundantMerge breaks syntax #86

Tietew opened this issue Dec 11, 2019 · 0 comments · Fixed by #89
Labels
bug Something isn't working

Comments

@Tietew
Copy link

Tietew commented Dec 11, 2019

After autocorrect following code, syntax will be broken.

def something
  hash.merge!({}) if blah?
  hash
end

Expected behavior

Should not break syntax.
Or give up autocorrection.

Actual behavior

def something
   if blah?
  hash
end

Steps to reproduce the problem

Put the code to test.rb then:

$ bundle exec rubocop test.rb -a --only Performance/RedundantMerge
Inspecting 1 file
E

Offenses:

test.rb:2:3: C: [Corrected] Performance/RedundantMerge: Use  instead of hash.merge!({}).
  hash.merge!({}) if blah?
  ^^^^^^^^^^^^^^^
test.rb:5:1: E: Lint/Syntax: unexpected token $end
(Using Ruby 2.6 parser; configure using TargetRubyVersion parameter, under AllCops)

1 file inspected, 2 offenses detected, 1 offense corrected

RuboCop version

0.77.0 (using Parser 2.6.5.0, running on ruby 2.6.5 x86_64-linux)

rubocop-performance is 1.5.1

@koic koic added the bug Something isn't working label Dec 19, 2019
koic added a commit to koic/rubocop-performance that referenced this issue Dec 19, 2019
…antMerge`

Fixes rubocop#86.

This PR fixes the following incorrect autocorrect for `Performance/RedundantMerge`
when using an empty hash argument.

```console
% cat example.rb
def something
  hash.merge!({}) if blah?
  hash
end

% rubocop --only Performance/RedundantMerge -a
Inspecting 1 file
E

Offenses:

example.rb:2:3: C: [Corrected] Performance/RedundantMerge: Use  instead
of hash.merge!({}).
  hash.merge!({}) if blah?
  ^^^^^^^^^^^^^^^
example.rb:5:1: E: Lint/Syntax: unexpected token $end
(Using Ruby 2.6 parser; configure using TargetRubyVersion parameter,
under AllCops)

1 file inspected, 2 offenses detected, 1 offense corrected

% cat example.rb
def something
   if blah?
  hash
end
```

There is no good case code to replace an empty hash argument,
so this PR changes it to not offense.
@koic koic closed this as completed in #89 Dec 21, 2019
koic added a commit that referenced this issue Dec 21, 2019
…undant_merge

[Fix #86] Fix an incorrect autocorrect for `Performance/RedundantMerge`
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants