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 #448] Fix a false positive for Performance/RedundantBlockCall #449

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
@@ -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