Skip to content

Commit

Permalink
Merge pull request #10785 from koic/fix_a_false_negative_for_style_re…
Browse files Browse the repository at this point in the history
…dundant_parentheses

Fix a false negative for `Style/RedundantParentheses`
  • Loading branch information
koic committed Jul 4, 2022
2 parents 8cc65d1 + 74ee625 commit 9577173
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
@@ -0,0 +1 @@
* [#10785](https://github.com/rubocop/rubocop/pull/10785): Fix a false negative for `Style/RedundantParentheses` when parens around a receiver of a method call with an argument. ([@koic][])
3 changes: 2 additions & 1 deletion lib/rubocop/cop/style/redundant_parentheses.rb
Expand Up @@ -81,7 +81,8 @@ def allowed_multiple_expression?(node)
end

def like_method_argument_parentheses?(node)
node.send_type? && node.arguments.size == 1 && !node.arithmetic_operation?
node.send_type? && node.arguments.one? &&
!node.arithmetic_operation? && node.first_argument.begin_type?
end

def empty_parentheses?(node)
Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cop/style/redundant_parentheses_spec.rb
Expand Up @@ -125,6 +125,17 @@
it_behaves_like 'plausible', '+(1.foo.bar)'
it_behaves_like 'plausible', '()'

it 'registers an offense for parens around a receiver of a method call with an argument' do
expect_offense(<<~RUBY)
(x).y(z)
^^^ Don't use parentheses around a method call.
RUBY

expect_correction(<<~RUBY)
x.y(z)
RUBY
end

it 'registers an offense for parens around an interpolated expression' do
expect_offense(<<~RUBY)
"\#{(foo)}"
Expand Down

0 comments on commit 9577173

Please sign in to comment.