Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numblock regressions in omit_parentheses Style/MethodCallWithArgsParentheses` #12648

Merged
merged 1 commit into from Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/fix_numblock_regressions_in_omit_parentheses.md
@@ -0,0 +1 @@
* [#12648](https://github.com/rubocop/rubocop/pull/12648): Fix numblock regressions in `omit_parentheses` `Style/MethodCallWithArgsParentheses`. ([@gsamokovarov][])
Expand Up @@ -132,7 +132,7 @@ def call_with_ambiguous_arguments?(node) # rubocop:disable Metrics/PerceivedComp
call_in_match_pattern?(node) ||
hash_literal_in_arguments?(node) ||
node.descendants.any? do |n|
n.forwarded_args_type? || n.block_type? ||
n.forwarded_args_type? || n.block_type? || n.numblock_type? ||
ambiguous_literal?(n) || logical_operator?(n)
end
end
Expand Down
18 changes: 18 additions & 0 deletions spec/rubocop/cop/style/method_call_with_args_parentheses_spec.rb
Expand Up @@ -771,6 +771,18 @@ def seatle_style arg: default(42)
expect_no_offenses('foo(1) { 2 }')
end

it 'accepts parens around argument values with blocks' do
expect_no_offenses(<<~RUBY)
Foo::Bar.find(pending.things.map { |t| t['code'] }.first)
RUBY
end

it 'accepts parens around argument values with numblocks', :ruby27 do
expect_no_offenses(<<~RUBY)
Foo::Bar.find(pending.things.map { _1['code'] })
RUBY
end

it 'accepts parens in array literal calls with blocks' do
expect_no_offenses(<<~RUBY)
[
Expand Down Expand Up @@ -1018,6 +1030,12 @@ def seatle_style arg: default(42)
expect_no_offenses('foo().bar(3).wait 4')
end

it 'accept parens when previously chained sends have numblocks', :ruby27 do
expect_no_offenses(<<~RUBY)
[a, b].map { _1.call 'something' }.uniq.join(' - ')
RUBY
end

it 'accepts parens in the last call if any previous calls with parentheses' do
expect_no_offenses('foo().bar(3).quux.wait(4)')
end
Expand Down