Skip to content

Commit

Permalink
[Fix #12524] Fix a false positive for `Style/MethodCallWithArgsParent…
Browse files Browse the repository at this point in the history
…heses`

Fixes #12524.

This PR fixes a false positive for `Style/MethodCallWithArgsParentheses`
when `EnforcedStyle: omit_parentheses` and parens in `when` clause is used to pass an argument.
  • Loading branch information
koic authored and bbatsov committed Dec 11, 2023
1 parent 0daa4aa commit 3bcc171
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#12524](https://github.com/rubocop/rubocop/issues/12524): Fix a false positive for `Style/MethodCallWithArgsParentheses` when `EnforcedStyle: omit_parentheses` and parens in `when` clause is used to pass an argument. ([@koic][])
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def parentheses_at_the_end_of_multiline_call?(node)

def legitimate_call_with_parentheses?(node) # rubocop:disable Metrics/PerceivedComplexity
call_in_literals?(node) ||
node.parent&.when_type? ||
call_with_ambiguous_arguments?(node) ||
call_in_logical_operators?(node) ||
call_in_optional_arguments?(node) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,14 @@ def seatle_style arg: default(42)
RUBY
end

it 'accepts parens in `when` clause is used to pass an argument' do
expect_no_offenses(<<-RUBY)
case condition
when do_something(arg)
end
RUBY
end

it 'autocorrects single-line calls' do
expect_offense(<<~RUBY)
top.test(1, 2, foo: bar(3))
Expand Down

0 comments on commit 3bcc171

Please sign in to comment.