Skip to content

autocorrect Performance/RedundantMerge breaks syntax #86

Closed
@Tietew

Description

@Tietew

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions