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

NestedParenthesizedCalls and MethodCallWithArgsParentheses autocorrect produces code with syntax error #9335

Closed
jonas054 opened this issue Jan 5, 2021 · 0 comments · Fixed by #9336
Labels

Comments

@jonas054
Copy link
Collaborator

jonas054 commented Jan 5, 2021

With the following code

# .rubocop.yml
AllCops:
  NewCops: enable

Style/FrozenStringLiteralComment:
  Enabled: false

Style/MethodCallWithArgsParentheses:
  Enabled: true
# file.rb
a(b 1)

running rubocop -a

Expected behavior

# file.rb
a(b(1))

Actual behavior

file.rb:1:3: C: [Corrected] Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.
a(b 1)
  ^^^
file.rb:1:3: C: [Corrected] Style/NestedParenthesizedCalls: Add parentheses to nested method call b 1.
a(b 1)
  ^^^
file.rb:1:8: E: Lint/Syntax: unexpected token tRPAREN
(Using Ruby 2.4 parser; configure using TargetRubyVersion parameter, under AllCops)
a(b(1)))
       ^
# file.rb
a(b(1)))

Steps to reproduce the problem

As above.

RuboCop version

$ rubocop -V
1.7.0 (using Parser 3.0.0.0, rubocop-ast 1.3.0, running on ruby 3.0.0 x86_64-linux)

I'm working on a fix for this myself. I think the easiest solution is to make Style/NestedParenthesizedCalls do nothing if Style/MethodCallWithArgsParentheses is enabled (which it isn't by default).

@jonas054 jonas054 added the bug label Jan 5, 2021
koic added a commit to koic/rubocop that referenced this issue Jan 5, 2021
…izedCalls`

Fixes rubocop#9335.

This PR fixes an incorrect auto-correct for `EnforcedStyle: require_parentheses` of
`Style/MethodCallWithArgsParentheses` with `Style/NestedParenthesizedCalls`.
bbatsov pushed a commit that referenced this issue Jan 6, 2021
Fixes #9335.

This PR fixes an incorrect auto-correct for `EnforcedStyle: require_parentheses` of
`Style/MethodCallWithArgsParentheses` with `Style/NestedParenthesizedCalls`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant