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

Fix an incorrect auto-correct for Style/RedundantParentheses #6995

Merged

Conversation

koic
Copy link
Member

@koic koic commented Apr 29, 2019

This PR fixes an incorrect auto-correct for Style/RedundantParentheses when enclosed in parentheses at while-post or until-post.

The following is a reproduction step.

% rubocop example1.rb --only Style/RedundantParentheses -a
Inspecting 1 file
E

Offenses:

example1.rb:3:5: E: Lint/Syntax: unexpected token tIDENTIFIER
(Using Ruby 2.2 parser; configure using TargetRubyVersion parameter,
under AllCops)
end whilefoo
    ^^^^^^^^
example1.rb:3:10: C: [Corrected] Style/RedundantParentheses:
Don't use parentheses around a method call.
end while(foo)
    ^^^^^

1 file inspected, 2 offenses detected, 1 offense corrected

This is a broken while.

% git diff
diff --git a/example1.rb b/example1.rb
index cf5523f..5f47ae4 100644
--- a/example1.rb
+++ b/example1.rb
@@ -1,3 +1,3 @@
 begin
   do_something
-end while(foo)
+end whilefoo

This will not be warned when while ... end.

% cat example2.rb
while(foo)
  do_something
end

% rubocop example2.rb --only Style/RedundantParentheses
Inspecting 1 file
.

1 file inspected, no offenses detected

So this PR changes to the same behavior.


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.

This PR fixes an incorrect auto-correct for `Style/RedundantParentheses`
when enclosed in parentheses at `while-post` or `until-post`.

The following is a reproduction step.

```console
% rubocop example1.rb --only Style/RedundantParentheses -a
Inspecting 1 file
E

Offenses:

example1.rb:3:5: E: Lint/Syntax: unexpected token tIDENTIFIER
(Using Ruby 2.2 parser; configure using TargetRubyVersion parameter,
under AllCops)
end whilefoo
    ^^^^^^^^
example1.rb:3:10: C: [Corrected] Style/RedundantParentheses:
Don't use parentheses around a method call.
end while(foo)
    ^^^^^

1 file inspected, 2 offenses detected, 1 offense corrected
```

This is a broken `while`.

```diff
% git diff
diff --git a/example1.rb b/example1.rb
index cf5523f..5f47ae4 100644
--- a/example1.rb
+++ b/example1.rb
@@ -1,3 +1,3 @@
 begin
   do_something
-end while(foo)
+end whilefoo
```

This will not be warned when `while` ... `end`.

```consle
% cat example2.rb
while(foo)
  do_something
end

% rubocop example2.rb --only Style/RedundantParentheses
Inspecting 1 file
.

1 file inspected, no offenses detected
```

So this PR changes to the same behavior.
@bbatsov bbatsov merged commit b0262a5 into rubocop:master Apr 29, 2019
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 29, 2019

👍

@koic koic deleted the fix_a_false_positive_for_redundant_parentheses branch April 29, 2019 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants