Skip to content

Commit 9d28120

Browse files
authored
Merge pull request #449 from koic/fix_false_positive_for_performance_redundant_block_call
[Fix #448] Fix a false positive for `Performance/RedundantBlockCall`
2 parents d4d1875 + 0d98285 commit 9d28120

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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][])

lib/rubocop/cop/performance/redundant_block_call.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def on_def(node)
4949
next unless body
5050

5151
calls_to_report(argname, body).each do |blockcall|
52+
next if blockcall.block_literal?
53+
5254
add_offense(blockcall, message: format(MSG, argname: argname)) do |corrector|
5355
autocorrect(corrector, blockcall)
5456
end

spec/rubocop/cop/performance/redundant_block_call_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ def method(&block)
117117
RUBY
118118
end
119119

120+
it 'accepts when using `block.call` with block argument' do
121+
expect_no_offenses(<<~RUBY)
122+
def method(&block)
123+
block.call { do_something }
124+
end
125+
RUBY
126+
end
127+
128+
it 'accepts when using `block.call` with numbered block argument' do
129+
expect_no_offenses(<<~RUBY)
130+
def method(&block)
131+
block.call { _1.do_something }
132+
end
133+
RUBY
134+
end
135+
120136
it 'accepts another block being passed along with other args' do
121137
expect_no_offenses(<<~RUBY)
122138
def method(&block)

0 commit comments

Comments
 (0)