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

Error with Style/Next cop #1923

Closed
scrozier opened this issue May 27, 2015 · 7 comments
Closed

Error with Style/Next cop #1923

scrozier opened this issue May 27, 2015 · 7 comments

Comments

@scrozier
Copy link

I don't know enough about the Rubocop code to give much direction, but I encountered this error and wanted to report it.

From the output:

app/models/user.rb:168:24: C: Style/Next: Use next to skip iteration.
    favorite_subassets.each do |s_id|
                       ^^^^

The -V:

0.28.0 (using Parser 2.2.0.2, running on ruby 2.2.0 x86_64-darwin14)

And the traceback:

An error occurred while Style/Next cop was inspecting /Users/steve/projects/TimeEntry/test/models/user_test.rb.
undefined method `loc' for nil:NilClass
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/lib/rubocop/cop/mixin/if_node.rb:14:in `ternary_op?'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/lib/rubocop/cop/style/next.rb:81:in `simple_if_without_break?'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/lib/rubocop/cop/style/next.rb:75:in `ends_with_condition?'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/lib/rubocop/cop/style/next.rb:52:in `on_for'
(eval):5:in `block (2 levels) in on_for'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/lib/rubocop/cop/commissioner.rb:92:in `with_cop_error_handling'
(eval):4:in `block in on_for'
(eval):2:in `each'
(eval):2:in `on_for'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:239:in `process'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:255:in `block in process_all'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:254:in `map'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:254:in `process_all'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/parser-2.2.0.2/lib/parser/ast/processor.rb:9:in `process_regular_node'
(eval):9:in `on_begin'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:239:in `process'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:255:in `block in process_all'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:254:in `map'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:254:in `process_all'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/parser-2.2.0.2/lib/parser/ast/processor.rb:9:in `process_regular_node'
(eval):9:in `on_block'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:239:in `process'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:255:in `block in process_all'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:254:in `map'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:254:in `process_all'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/parser-2.2.0.2/lib/parser/ast/processor.rb:9:in `process_regular_node'
(eval):9:in `on_begin'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:239:in `process'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:255:in `block in process_all'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:254:in `map'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:254:in `process_all'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/parser-2.2.0.2/lib/parser/ast/processor.rb:9:in `process_regular_node'
(eval):9:in `on_class'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:239:in `process'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:255:in `block in process_all'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:254:in `map'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:254:in `process_all'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/parser-2.2.0.2/lib/parser/ast/processor.rb:9:in `process_regular_node'
(eval):9:in `on_begin'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:239:in `process'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/lib/rubocop/cop/commissioner.rb:52:in `investigate'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/lib/rubocop/cop/team.rb:33:in `inspect_file'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/lib/rubocop/runner.rb:92:in `inspect_file'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/lib/rubocop/runner.rb:76:in `block in do_inspection_loop'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/lib/rubocop/runner.rb:71:in `loop'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/lib/rubocop/runner.rb:71:in `do_inspection_loop'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/lib/rubocop/runner.rb:58:in `process_file'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/lib/rubocop/runner.rb:27:in `block in run'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/lib/rubocop/runner.rb:25:in `each'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/lib/rubocop/runner.rb:25:in `run'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/lib/rubocop/cli.rb:24:in `run'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/bin/rubocop:13:in `block in <top (required)>'
/Users/steve/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.28.0/bin/rubocop:12:in `<top (required)>'
/Users/steve/.rvm/gems/ruby-2.2.0/bin/rubocop:23:in `load'
/Users/steve/.rvm/gems/ruby-2.2.0/bin/rubocop:23:in `<main>'
/Users/steve/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `eval'
/Users/steve/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `<main>'
@bbatsov
Copy link
Collaborator

bbatsov commented May 27, 2015

Update your RuboCop. This issue was likely fixed by now.

@scrozier
Copy link
Author

Updated to 0.31.0. Same error.

@bbatsov
Copy link
Collaborator

bbatsov commented May 27, 2015

Please, isolate some minimal repro case, so we can take a look at the problem.

@scrozier
Copy link
Author

Running rubocop against this input will reproduce the error:

for i in [1]
end

@scrozier
Copy link
Author

Here's the 0.31.0 traceback:

undefined method `loc' for nil:NilClass
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/cop/mixin/if_node.rb:14:in `ternary_op?'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/cop/style/next.rb:71:in `simple_if_without_break?'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/cop/style/next.rb:65:in `ends_with_condition?'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/cop/style/next.rb:53:in `on_for'
(eval):5:in `block (2 levels) in on_for'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/cop/commissioner.rb:92:in `with_cop_error_handling'
(eval):4:in `block in on_for'
(eval):2:in `each'
(eval):2:in `on_for'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/ast-2.0.0/lib/ast/processor.rb:239:in `process'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/cop/commissioner.rb:52:in `investigate'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/cop/team.rb:33:in `inspect_file'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/runner.rb:129:in `inspect_file'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/runner.rb:100:in `block in do_inspection_loop'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/runner.rb:94:in `loop'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/runner.rb:94:in `do_inspection_loop'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/runner.rb:72:in `process_file'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/runner.rb:53:in `block in inspect_files'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/runner.rb:51:in `each'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/runner.rb:51:in `inspect_files'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/runner.rb:30:in `run'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/lib/rubocop/cli.rb:26:in `run'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/bin/rubocop:13:in `block in <top (required)>'
/Users/steve/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
/Users/steve/.rvm/gems/ruby-2.2.0/gems/rubocop-0.31.0/bin/rubocop:12:in `<top (required)>'
/Users/steve/.rvm/gems/ruby-2.2.0/bin/rubocop:23:in `load'
/Users/steve/.rvm/gems/ruby-2.2.0/bin/rubocop:23:in `<main>'
/Users/steve/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `eval'
/Users/steve/.rvm/gems/ruby-2.2.0/bin/ruby_executable_hooks:15:in `<main>'

@bbatsov
Copy link
Collaborator

bbatsov commented May 28, 2015

Issue fixed. I'm wondering why you had for without a body in your code. A bug maybe?

@scrozier
Copy link
Author

Well, not exactly a bug, but yes, a remnant of code accidentally left in.

Thanks for the fix, and for the tool!

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