diff --git a/changelog/fix_allow_parentheses_in_yield_arguments_with_style_method_call_with_args_parentheses.md b/changelog/fix_allow_parentheses_in_yield_arguments_with_style_method_call_with_args_parentheses.md new file mode 100644 index 00000000000..a69a8e6b22b --- /dev/null +++ b/changelog/fix_allow_parentheses_in_yield_arguments_with_style_method_call_with_args_parentheses.md @@ -0,0 +1 @@ +* [#9625](https://github.com/rubocop/rubocop/pull/9625): Allow parentheses in yield arguments with `Style/MethodCallWithArgsParentheses` `EnforcedStyle: omit_parentheses` to fix invalid Ruby auto-correction. ([@gsamokovarov][]) diff --git a/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb b/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb index ce15f324d48..839ef7c9339 100644 --- a/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb +++ b/lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb @@ -114,7 +114,7 @@ def call_with_braced_block?(node) def call_as_argument_or_chain?(node) node.parent && (node.parent.send_type? && !assigned_before?(node.parent, node) || - node.parent.csend_type? || node.parent.super_type?) + node.parent.csend_type? || node.parent.super_type? || node.parent.yield_type?) end def hash_literal_in_arguments?(node) diff --git a/spec/rubocop/cop/style/method_call_with_args_parentheses_spec.rb b/spec/rubocop/cop/style/method_call_with_args_parentheses_spec.rb index 2236e3b68b1..b9bf2d627f2 100644 --- a/spec/rubocop/cop/style/method_call_with_args_parentheses_spec.rb +++ b/spec/rubocop/cop/style/method_call_with_args_parentheses_spec.rb @@ -658,6 +658,11 @@ def seatle_style arg: default(42) expect_no_offenses('foo &block') end + it 'accepts parens in yield argument method calls' do + expect_no_offenses('yield File.basepath(path)') + expect_no_offenses('yield path, File.basepath(path)') + end + it 'accepts parens in super without args' do expect_no_offenses('super()') end