Skip to content

Commit

Permalink
Merge pull request #266 from koic/false_negative_for_performance_redu…
Browse files Browse the repository at this point in the history
…ndant_block_call

[Fix #261] Fix a false negative for `Performance/RedundantBlockCall`
  • Loading branch information
koic committed Oct 23, 2021
2 parents e227e1c + d85f59c commit 9feae4b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
@@ -0,0 +1 @@
* [#261](https://github.com/rubocop/rubocop-performance/issues/261): Fix a false negative for `Performance/RedundantBlockCall` when using `block.call` in a class method'. ([@koic][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/performance/redundant_block_call.rb
Expand Up @@ -55,6 +55,7 @@ def on_def(node)
end
end
end
alias on_defs on_def

private

Expand Down
15 changes: 15 additions & 0 deletions spec/rubocop/cop/performance/redundant_block_call_spec.rb
Expand Up @@ -31,6 +31,21 @@ def method(&block)
RUBY
end

it 'registers and corrects an offense when using `block.call` in a class method' do
expect_offense(<<~RUBY)
def self.method(&block)
block.call
^^^^^^^^^^ Use `yield` instead of `block.call`.
end
RUBY

expect_correction(<<~RUBY)
def self.method(&block)
yield
end
RUBY
end

it 'registers and autocorrects an offense when `block.call` with arguments' do
expect_offense(<<~RUBY)
def method(&block)
Expand Down

0 comments on commit 9feae4b

Please sign in to comment.