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

Style/Next cop throws an exception when autocorrectting #2661

Closed
tobypinder opened this issue Jan 18, 2016 · 0 comments
Closed

Style/Next cop throws an exception when autocorrectting #2661

tobypinder opened this issue Jan 18, 2016 · 0 comments

Comments

@tobypinder
Copy link

This cop specifically seems to consistently throw an exception while autocorrecting.

It works fine without --auto-correct

  ➜  rubocop --only Style/Next               

  11  Style/Next
  --
  11  Total

But with, it throws exception.

  ➜  rubocop --only Style/Next --auto-correct

  --
  0  Total

  undefined method `end_pos' for nil:NilClass
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/cop/style/next.rb:135:in `end_range'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/cop/style/next.rb:118:in `block in autocorrect'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/cop/corrector.rb:47:in `block in rewrite'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/cop/corrector.rb:46:in `each'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/cop/corrector.rb:46:in `rewrite'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/cop/team.rb:91:in `autocorrect_one_cop'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/cop/team.rb:68:in `autocorrect'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/cop/team.rb:39:in `inspect_file'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/runner.rb:194:in `inspect_file'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rub
➜  ocop-0.36.0/lib/rubocop/runner.rb:164:in `block in do_inspection_loop'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/runner.rb:158:in `loop'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/runner.rb:158:in `do_inspection_loop'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/runner.rb:87:in `process_file'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/runner.rb:59:in `block in inspect_files'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/runner.rb:57:in `each'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/runner.rb:57:in `inspect_files'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/runner.rb:35:in `run'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0/gems/rubocop-0.36.0/lib/rubocop/cli.rb:30:in `run'
  /home/toby/.rvm/gems/ruby-2.3.0@global/gems/rubocop-0.36.0/bin/rubocop:14:in `block in <top (required)>'
  /home/toby/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
  /home/toby/.rvm/gems/ruby-2.3.0@global/gems/rubocop-0.36.0/bin/rubocop:13:in `<top (required)>'
  /home/toby/.rvm/gems/ruby-2.3.0@cerebro/bin/rubocop:23:in `load'
  /home/toby/.rvm/gems/ruby-2.3.0@cerebro/bin/rubocop:23:in `<main>'
  /home/toby/.rvm/gems/ruby-2.3.0@cerebro/bin/ruby_executable_hooks:15:in `eval'
  /home/toby/.rvm/gems/ruby-2.3.0@cerebro/bin/ruby_executable_hooks:15:in `<main>'

This seems to happen every time for me, but just to be sure it can be reliably produced when running Rubocop on the following test code

module RubocopNextExample
  def do_things(things)
    things.each do |thing|
      fail "Lorem Ipsum" unless thing.include?('foo')
    end
  end
end

System

➜  rubocop -V
0.36.0 (using Parser 2.3.0.1, running on ruby 2.3.0 x86_64-linux)
➜  ruby -v   
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
@tobypinder tobypinder changed the title Style/Next cop - exception on autocorrect Style/Next cop throws an exception when autocorrectting Jan 18, 2016
bbatsov added a commit that referenced this issue Jan 18, 2016
[Fix #2661] Fix auto-correcting modifiers in Next
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

1 participant