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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#6995](https://github.com/rubocop-hq/rubocop/pull/6995): Fix an incorrect auto-correct for `Style/RedundantParentheses` when enclosed in parentheses at `while-post` or `until-post`. ([@koic][])

## 0.68.0 (2019-04-29)

### New features
Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/cop/style/redundant_parentheses.rb
Expand Up @@ -28,6 +28,8 @@ class RedundantParentheses < Cop

def on_begin(node)
return if !parentheses?(node) || parens_allowed?(node)
return if node.parent && (node.parent.while_post_type? ||
node.parent.until_post_type?)

check(node)
end
Expand Down
16 changes: 16 additions & 0 deletions spec/rubocop/cop/style/redundant_parentheses_spec.rb
Expand Up @@ -197,6 +197,22 @@ def x
RUBY
end

it 'accepts parentheses when enclosed in parentheses at `while-post`' do
expect_no_offenses(<<-RUBY.strip_indent)
begin
do_something
end while(bar)
RUBY
end

it 'accepts parentheses when enclosed in parentheses at `until-post`' do
expect_no_offenses(<<-RUBY.strip_indent)
begin
do_something
end until(bar)
RUBY
end

it 'accepts parentheses when they touch the preceding keyword' do
expect_no_offenses('if x; y else(1) end')
end
Expand Down