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

Performance/RedundantBlockCall is yield when "yield" keyword is not applicable #2986

Closed
timnew opened this issue Mar 26, 2016 · 1 comment
Closed

Comments

@timnew
Copy link

timnew commented Mar 26, 2016

I have code described as following

class Foo
  attr_reader :proc

  def method(arg, &block)
    block.call(arg, &proc) # Rubocop warns Performance/RedundantBlockCall here
  end
end

Rubocop warns on the block.call, and ask to use yield rather than Proc#call.
But in fact, yield is not applicable here since yield doesn't accept block.

So I think Rubocop should check whether another block is passed before
complains Performance/RedundantBlockCall

RuboCop version

$ rubocop -V
0.37.2 (using Parser 2.3.0.6, running on ruby 2.2.3 x86_64-darwin14)
@timnew timnew changed the title Performance/RedundantBlockCall warns when yield is not applicable Performance/RedundantBlockCall still complain when yield keyword is not applicable Mar 26, 2016
@timnew timnew changed the title Performance/RedundantBlockCall still complain when yield keyword is not applicable Performance/RedundantBlockCall is yield when "yield" keyword is not applicable Mar 26, 2016
@halostatue
Copy link

This is also present on other code that it cannot apply to:

def verify_destination(name, destination, &notify)
  notify ||= ->(message) { warn message }

  destination.dig(:path) ||
    notify.("Destination #{name} invalid: No path present")
  destination.dig(:credentials, :provider) ||
    notify.("Destination #{name} invalid: No provider present")
end

I cannot yield because:

def foo(&block)
  block ||= ->(m) { warn m }
  yield "hello"
end  

foo
LocalJumpError: no block given (yield)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants