Skip to content

Commit

Permalink
[Fix rubocop#10719] Fix a false positive for `Lint/ParenthesesAsGroup…
Browse files Browse the repository at this point in the history
…edExpression`

Fixes rubocop#10719 and follow up rubocop#8039.

This PR fixes a false positive for `Lint/ParenthesesAsGroupedExpression`
when using safe navigation operator.
  • Loading branch information
koic committed Jun 17, 2022
1 parent 6dd57ef commit 8653aa9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
@@ -0,0 +1 @@
* [#10719](https://github.com/rubocop/rubocop/issues/10719): Fix a false positive for `Lint/ParenthesesAsGroupedExpression` when using safe navigation operator. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb
Expand Up @@ -55,7 +55,7 @@ def first_argument_starts_with_left_parenthesis?(node)

def chained_calls?(node)
first_argument = node.first_argument
first_argument.send_type? && (node.children.last&.children&.count || 0) > 1
first_argument.call_type? && (node.children.last&.children&.count || 0) > 1
end

def ternary_expression?(node)
Expand Down
Expand Up @@ -36,6 +36,12 @@
RUBY
end

it 'does not register an offense for expression followed by chained expression with safe navigation operator' do
expect_no_offenses(<<~RUBY)
func (x).func.func.func.func&.func
RUBY
end

it 'does not register an offense for math expression' do
expect_no_offenses(<<~RUBY)
puts (2 + 3) * 4
Expand Down

0 comments on commit 8653aa9

Please sign in to comment.