Rubocop: Style/RedundantParentheses should ignore yielding hash literal

Created on 24 Jun 2020  路  1Comment  路  Source: rubocop-hq/rubocop

With a method like:

def foo
  yield ({
    a: 6,
    b: 7,
  })
end

Runningrubocop -a autocorrects this to:

def foo
  yield {
    a: 6,
    b: 7,
  }
end

And gives this output:

app/test.rb:4:9: E: Lint/Syntax: unexpected token tLCURLY
(Using Ruby 2.5 parser; configure using TargetRubyVersion parameter, under AllCops)
  yield {
        ^
app/test.rb:4:9: C: [Corrected] Style/RedundantParentheses: Don't use parentheses around a literal.
  yield ({ ...
        ^^

When running this auto-corrected file, I get a syntax error:

app/test.rb:4: syntax error, unexpected '{'
  yield {
        ^

I believe the Style/RedundantParentheses cop should not consider parentheses in this situation to be redundant

$ rubocop -V
0.86.0 (using Parser 2.7.1.4, rubocop-ast 0.0.3, running on ruby 2.5.1 x86_64-darwin18)
bug good first issue help wanted

Most helpful comment

I will look into a fix for this

>All comments

I will look into a fix for this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

printercu picture printercu  路  3Comments

AndreiMotinga picture AndreiMotinga  路  3Comments

Aqualon picture Aqualon  路  3Comments

bquorning picture bquorning  路  3Comments

ecbrodie picture ecbrodie  路  3Comments