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

[Fix #86] Fix an incorrect autocorrect for Performance/RedundantMerge #89

Merged

Conversation

koic
Copy link
Member

@koic koic commented Dec 19, 2019

Fixes #86.

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

% 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.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

…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 merged commit 19c7b96 into rubocop:master Dec 21, 2019
@koic koic deleted the fix_an_incorrect_autocorrect_for_redundant_merge branch December 21, 2019 17:10
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

autocorrect Performance/RedundantMerge breaks syntax
1 participant