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 reporting false positive for a return inside a lambda inside RSpec.configure #1803

Closed
DMA57361 opened this issue Apr 17, 2015 · 3 comments · Fixed by #1920

Comments

@DMA57361
Copy link

We have the following in the spec helper of one of our projects, to ignore a deprecation warning that we'll keep getting until the next big version of a gem we use is released:

RSpec.configure do |config|
  # some configuration

  if Gem.loaded_specs["paper_trail"].version < Gem::Version.new("4.0.0")
    current_behavior = ActiveSupport::Deprecation.behavior
    ActiveSupport::Deprecation.behavior = lambda do |message, callstack|
      return if message =~ /`serialized_attributes` is deprecated without replacement/ && callstack.any? { |m| m =~ /paper_trail/ }
      Array.wrap(current_behavior).each { |behavior| behavior.call(message, callstack) }
    end
  end

  # more configuration
end

Version 0.30.0 of RuboCop is reporting the following:

spec/spec_helper.rb:36:7: W: Non-local exit from iterator, without return value. next, break, Array#find, Array#any?, etc. is preferred.
      return if message =~ /`serialized_attributes` is deprecated without replacement/ && callstack.any? { |m| m =~ /paper_trail/ }

There's no iterator here, so this looks like is could be a false positive.

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 22, 2015

//cc @ypresto

@ypresto
Copy link
Contributor

ypresto commented Apr 22, 2015

It is false positive without fail, as return in lambda just continues from next line of lambda#call and harmless. It should be fixed somehow.

@ngan
Copy link

ngan commented Apr 23, 2015

This is also a problem for the -> lambda syntax as well.

ypresto added a commit to ypresto/rubocop that referenced this issue May 26, 2015
ypresto added a commit to ypresto/rubocop that referenced this issue May 27, 2015
bbatsov added a commit that referenced this issue May 27, 2015
…-positive

[Fix #1803] Don't warn for return from lambda
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

Successfully merging a pull request may close this issue.

4 participants