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

Bug: Invalid autocorrection interaction between Lint/ParenthesesAsGroupedExpression & Style/RedundantParentheses #8572

Closed
searls opened this issue Aug 23, 2020 · 0 comments · Fixed by #8638
Labels

Comments

@searls
Copy link

searls commented Aug 23, 2020

In Standard @sethherr noticed an undesired interaction between the safe autocorrections of Lint/ParenthesesAsGroupedExpression and Style/RedundantParentheses (both enabled-by-default): standardrb/standard#192


Expected behavior

Here's the starting code example:

do_something (foo)

Here's what happens when I run only Lint/ParenthesesAsGroupedExpression and Style/RedundantParentheses:

$ rubocop --only "Lint/ParenthesesAsGroupedExpression,Style/RedundantParentheses" foo.rb 
Inspecting 1 file
W

Offenses:

foo.rb:1:13: W: Lint/ParenthesesAsGroupedExpression: (...) interpreted as grouped expression.
do_something (foo)
            ^
foo.rb:1:14: C: Style/RedundantParentheses: Don't use parentheses around a method call.
do_something (foo)
             ^^^^^

1 file inspected, 2 offenses detected

My expectation is the autocorrect would ultimately result in either do_something foo or do_something(foo)

Actual behavior

When running the same command with autocorrect, this is what we get:

$ be rubocop --only "Lint/ParenthesesAsGroupedExpression,Style/RedundantParentheses" -a foo.rb
Inspecting 1 file
W

Offenses:

foo.rb:1:13: W: [Corrected] Lint/ParenthesesAsGroupedExpression: (...) interpreted as grouped expression.
do_something (foo)
            ^
foo.rb:1:14: C: [Corrected] Style/RedundantParentheses: Don't use parentheses around a method call.
do_something (foo)
             ^^^^^

1 file inspected, 2 offenses detected, 2 offenses corrected

And now the result is definitely wrong:

$ cat foo.rb 
do_somethingfoo

Steps to reproduce the problem

I hope the instructions above are a clear enough minimal reproduction

RuboCop version

$ rubocop -V
0.89.1 (using Parser 2.7.1.4, rubocop-ast 0.3.0, running on ruby 2.7.1 x86_64-darwin19)
@koic koic added the bug label Aug 24, 2020
koic added a commit to koic/rubocop that referenced this issue Sep 3, 2020
Fixes rubocop#8572.

This PR fixes a false positive for `Style/RedundantParentheses`
when like method argument parentheses.
bbatsov pushed a commit that referenced this issue Sep 3, 2020
Fixes #8572.

This PR fixes a false positive for `Style/RedundantParentheses`
when like method argument parentheses.
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.

2 participants