Skip to content

Commit

Permalink
[Fix rubocop#12124] Fix false positives for Style/RedundantParentheses
Browse files Browse the repository at this point in the history
Fixes rubocop#12124.

This PR fixes false positives for `Style/RedundantParentheses` when
parentheses in `super` or `yield` call with multiline style argument.
  • Loading branch information
koic committed Aug 16, 2023
1 parent aba8895 commit 859dac7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12124](https://github.com/rubocop/rubocop/issues/12124): Fix false positives for `Style/RedundantParentheses` when parentheses in `super` or `yield` call with multiline style argument. ([@koic][])
4 changes: 3 additions & 1 deletion lib/rubocop/cop/style/redundant_parentheses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def ternary_parentheses_required?
end

def like_method_argument_parentheses?(node)
node.send_type? && node.arguments.one? && !node.parenthesized? &&
return false if !node.send_type? && !node.super_type? && !node.yield_type?

node.arguments.one? && !node.parenthesized? &&
!node.arithmetic_operation? && node.first_argument.begin_type?
end

Expand Down
16 changes: 16 additions & 0 deletions spec/rubocop/cop/style/redundant_parentheses_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,22 @@ def x
RUBY
end

it 'accepts parentheses in super call with multiline style argument' do
expect_no_offenses(<<~RUBY)
super (
42
)
RUBY
end

it 'accepts parentheses in yield call with multiline style argument' do
expect_no_offenses(<<~RUBY)
yield (
42
)
RUBY
end

it 'registers an offense and corrects when method arguments are unnecessarily parenthesized' do
expect_offense(<<~RUBY)
foo(
Expand Down

0 comments on commit 859dac7

Please sign in to comment.