Skip to content

Commit

Permalink
Merge pull request #449 from koic/fix_false_positive_for_performance_…
Browse files Browse the repository at this point in the history
…redundant_block_call

[Fix #448] Fix a false positive for `Performance/RedundantBlockCall`
  • Loading branch information
koic committed Mar 29, 2024
2 parents d4d1875 + 0d98285 commit 9d28120
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
@@ -0,0 +1 @@
* [#448](https://github.com/rubocop/rubocop-performance/issues/448): Fix a false positive for `Performance/RedundantBlockCall` when using `block.call` with block argument. ([@koic][])
2 changes: 2 additions & 0 deletions lib/rubocop/cop/performance/redundant_block_call.rb
Expand Up @@ -49,6 +49,8 @@ def on_def(node)
next unless body

calls_to_report(argname, body).each do |blockcall|
next if blockcall.block_literal?

add_offense(blockcall, message: format(MSG, argname: argname)) do |corrector|
autocorrect(corrector, blockcall)
end
Expand Down
16 changes: 16 additions & 0 deletions spec/rubocop/cop/performance/redundant_block_call_spec.rb
Expand Up @@ -117,6 +117,22 @@ def method(&block)
RUBY
end

it 'accepts when using `block.call` with block argument' do
expect_no_offenses(<<~RUBY)
def method(&block)
block.call { do_something }
end
RUBY
end

it 'accepts when using `block.call` with numbered block argument' do
expect_no_offenses(<<~RUBY)
def method(&block)
block.call { _1.do_something }
end
RUBY
end

it 'accepts another block being passed along with other args' do
expect_no_offenses(<<~RUBY)
def method(&block)
Expand Down

0 comments on commit 9d28120

Please sign in to comment.