Skip to content

Commit

Permalink
[Fix rubocop#261] Fix a false negative for `Performance/RedundantBloc…
Browse files Browse the repository at this point in the history
…kCall`

Fixes rubocop#261.

This PR fixes a false negative for `Performance/RedundantBlockCall`
when using `block.call` in a class method'.
  • Loading branch information
koic committed Oct 22, 2021
1 parent 40ef101 commit d85f59c
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 d85f59c

Please sign in to comment.