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

Rails/Blank cop: undefined method `type' for nil:NilClass #4171

Closed
doits opened this issue Mar 26, 2017 · 1 comment · Fixed by #4190
Closed

Rails/Blank cop: undefined method `type' for nil:NilClass #4171

doits opened this issue Mar 26, 2017 · 1 comment · Fixed by #4190
Labels

Comments

@doits
Copy link

doits commented Mar 26, 2017

The following file crashes rubocop with enabled Rails linters:

class Something
  def meth
    something || blub
  end
end
rubocop -R bla.rb
An error occurred while Rails/Blank cop was inspecting /Users/markus/svn/bla.rb:3:4.
undefined method `type' for nil:NilClass
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/cop/rails/blank.rb:45:in `nil_or_empty?'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/cop/rails/blank.rb:79:in `on_or'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/cop/commissioner.rb:43:in `block (2 levels) in on_or'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/cop/commissioner.rb:106:in `with_cop_error_handling'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/cop/commissioner.rb:42:in `block in on_or'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/cop/commissioner.rb:41:in `each'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/cop/commissioner.rb:41:in `on_or'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/ast/traversal.rb:95:in `on_def'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/cop/commissioner.rb:47:in `on_def'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/ast/traversal.rb:88:in `on_class'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/cop/commissioner.rb:47:in `on_class'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/ast/traversal.rb:12:in `walk'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/cop/commissioner.rb:60:in `investigate'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/cop/team.rb:124:in `investigate'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/cop/team.rb:112:in `offenses'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/cop/team.rb:54:in `inspect_file'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/runner.rb:248:in `inspect_file'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/runner.rb:195:in `block in do_inspection_loop'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/runner.rb:227:in `block in iterate_until_no_changes'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/runner.rb:220:in `loop'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/runner.rb:220:in `iterate_until_no_changes'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/runner.rb:191:in `do_inspection_loop'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/runner.rb:101:in `block in file_offenses'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/runner.rb:111:in `file_offense_cache'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/runner.rb:99:in `file_offenses'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/runner.rb:90:in `process_file'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/runner.rb:68:in `block in each_inspected_file'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/runner.rb:65:in `each'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/runner.rb:65:in `reduce'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/runner.rb:65:in `each_inspected_file'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/runner.rb:57:in `inspect_files'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/runner.rb:36:in `run'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/cli.rb:72:in `execute_runner'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/lib/rubocop/cli.rb:27:in `run'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/bin/rubocop:13:in `block in <top (required)>'
/usr/local/Cellar/ruby/2.4.0/lib/ruby/2.4.0/benchmark.rb:308:in `realtime'
/usr/local/lib/ruby/gems/2.4.0/gems/rubocop-0.48.0/bin/rubocop:12:in `<top (required)>'
/usr/local/bin/rubocop:22:in `load'
/usr/local/bin/rubocop:22:in `<main>'

RuboCop version

0.48.0 (using Parser 2.4.0.0, running on ruby 2.4.0 x86_64-darwin16)
@bbatsov bbatsov added the bug label Mar 26, 2017
Drenmi added a commit to Drenmi/rubocop that referenced this issue Mar 27, 2017
…`or` is a naked falsiness check

This cop would break if the RHS of the `||`` operator was a naked
falsiness check, e.g.:

```
foo.nil? || bar
```

This change fixes that.
@dworld-software
Copy link

@Drenmi Same error occurs on this code after your commits.

class Something
  def meth
    something || !blub
  end
end

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