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

RedundantBlockCall false positive with nested blocks #162

Closed
vlad-pisanov opened this issue Aug 30, 2020 · 0 comments · Fixed by #220
Closed

RedundantBlockCall false positive with nested blocks #162

vlad-pisanov opened this issue Aug 30, 2020 · 0 comments · Fixed by #220
Labels
bug Something isn't working

Comments

@vlad-pisanov
Copy link
Contributor

When the block argument is shadowed by a nested block argument, RedundantBlockCall cop is triggered. Consider:

def false_positive(&block)
  proc { p 'hi' }.then do |block|
    block.call
  end
end

The above triggers the cop. It gets wrongly auto-corrected to:

def false_positive()
  proc { p 'hi' }.then do |_block|
    yield
  end
end

(however, regular shadowed variables are correctly handled and don't trigger the cop):

def works(&block)
  block = proc { p 'hi' }
  block.call
end

Expected behavior

Should not trigger RedundantBlockCall

Actual behavior

Performance/RedundantBlockCall: Use yield instead of block.call

Steps to reproduce the problem

Run the false_positive code

RuboCop version

0.89.1 (using Parser 2.7.1.4, rubocop-ast 0.3.0, running on ruby 2.4.5 x86_64-darwin19)
@Darhazer Darhazer added the bug Something isn't working label Jan 17, 2021
koic added a commit to koic/rubocop-performance that referenced this issue Mar 2, 2021
…kCall`

Fixes rubocop#162.

This PR fixes a false positive for `Performance/RedundantBlockCall`
when an optional block that is overridden by block variable.
@koic koic closed this as completed in #220 Mar 3, 2021
koic added a commit that referenced this issue Mar 3, 2021
…redundant_block_call

[Fix #162] Fix a false positive for `Performance/RedundantBlockCall`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants