Skip to content

Commit

Permalink
Merge pull request rubocop#13019 from koic/fix_a_false_positive_for_s…
Browse files Browse the repository at this point in the history
…tyle_method_call_with_args_parentheses_cop

[Fix rubocop#13018] Fix a false positive for `Style/MethodCallWithArgsParentheses`
  • Loading branch information
koic committed Jun 24, 2024
2 parents 2d73bea + a02d3ca commit 1930f0e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#13018](https://github.com/rubocop/rubocop/issues/13018): Fix a false positive for `Style/MethodCallWithArgsParentheses` when `EnforcedStyle: omit_parentheses` is set and parenthesized method call is used before constant resolution. ([@koic][])
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def omit_parentheses(node) # rubocop:disable Metrics/PerceivedComplexity
return if inside_endless_method_def?(node)
return if require_parentheses_for_hash_value_omission?(node)
return if syntax_like_method_call?(node)
return if method_call_before_constant_resolution?(node)
return if super_call_without_arguments?(node)
return if legitimate_call_with_parentheses?(node)
return if allowed_camel_case_method_call?(node)
Expand Down Expand Up @@ -63,6 +64,10 @@ def syntax_like_method_call?(node)
node.implicit_call? || node.operator_method?
end

def method_call_before_constant_resolution?(node)
node.parent&.const_type?
end

def super_call_without_arguments?(node)
node.super_type? && node.arguments.none?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,12 @@ class Point < Struct.new :x, :y
RUBY
end

it 'accepts parenthesized method calls before constant resolution' do
expect_no_offenses(<<~RUBY)
do_something(arg)::CONST
RUBY
end

it 'accepts parens in single-line inheritance' do
expect_no_offenses(<<-RUBY)
class Point < Struct.new(:x, :y); end
Expand Down

0 comments on commit 1930f0e

Please sign in to comment.