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

Lint/NonLocalExitFromIterator false positive #3855

Closed
zachlatta opened this issue Jan 3, 2017 · 2 comments
Closed

Lint/NonLocalExitFromIterator false positive #3855

zachlatta opened this issue Jan 3, 2017 · 2 comments
Labels

Comments

@zachlatta
Copy link

I think I'm get a false positive from Lint/NonLocalExitFromIterator in the below code:

VCR.configure do |c|
  # ...

  def server_cookies(response)
    raw_cookies = response.headers['Set-Cookie']
    return if raw_cookies.nil? || raw_cookies.empty?

    raw_cookies.map { |ck| parse_server_cookie(ck) }
  end
end

Expected behavior

No flags should be raised.

Actual behavior

It's flagged with:

W: Non-local exit from iterator, without return value. next, break, Array#find, Array#any?, etc. is preferred.

Curiously, this only seems to happen when there's a block argument specified in the VCR.configure block – try omitting |c| to see what I mean.

Steps to reproduce the problem

  1. Create a file with the above code snippet as its contents
  2. Run Rubocop on it

RuboCop version

Include the output of rubocop -V. Here's an example:

bundle exec rubocop -V
0.46.0 (using Parser 2.3.3.1, running on ruby 2.3.1 x86_64-linux)
@Drenmi
Copy link
Collaborator

Drenmi commented Jan 4, 2017

Nice find @zachlatta! I think the reason we've missed this is that it's a pretty uncommon (at least to me) edge case. But there's no reason why we couldn't account for this, that I can see. 😀

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 4, 2017

Yeah, that should be easy to fix.

@bbatsov bbatsov added the bug label Jan 4, 2017
Drenmi added a commit to Drenmi/rubocop that referenced this issue Jan 21, 2017
…method definitions

This cop would report an offense if it found a `return` statement inside
a method definition inside a block, even though the `return` is scoped
to the method definition. This change fixes that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants