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/CaseLikeIf: undefined method `begin_type?' for nil:NilClass #9599

Closed
mscrivo opened this issue Mar 14, 2021 · 0 comments
Closed

Style/CaseLikeIf: undefined method `begin_type?' for nil:NilClass #9599

mscrivo opened this issue Mar 14, 2021 · 0 comments
Labels

Comments

@mscrivo
Copy link

@mscrivo mscrivo commented Mar 14, 2021

When using include?(module) in an if statement within a singleton class method, Rubocop fails with the following error:

An error occurred while Style/CaseLikeIf cop was inspecting /path/to/offending/file.rb

The issue is the missing qualifier in front of the include? If you put self. in front of the include? it no longer fails, but then the Style/RedundantSelf complains of a redundant self


Expected behavior

It should parse and handle this case fine.

Actual behavior

It fails to parse the file with the following debug output:

For /Users/michaelscrivo/affinity: configuration from /Users/michaelscrivo/affinity/.rubocop.yml
configuration from /Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-performance-1.10.1/config/default.yml
configuration from /Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-performance-1.10.1/config/default.yml
Default configuration from /Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/config/default.yml
configuration from /Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-rake-0.5.1/config/default.yml
configuration from /Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-rake-0.5.1/config/default.yml
configuration from /Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.10.3/config/default.yml
configuration from /Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-minitest-0.10.3/config/default.yml
Inspecting 1 file
Scanning /Users/michaelscrivo/affinity/lib/workers/base.rb
An error occurred while Style/CaseLikeIf cop was inspecting /Users/michaelscrivo/affinity/lib/workers/base.rb:9:8.
undefined method `begin_type?' for nil:NilClass
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/style/case_like_if.rb:222:in `deparenthesize'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/style/case_like_if.rb:108:in `find_target_in_send_node'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/style/case_like_if.rb:94:in `find_target'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/style/case_like_if.rb:38:in `on_if'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/commissioner.rb:100:in `public_send'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/commissioner.rb:100:in `block (2 levels) in trigger_responding_cops'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/commissioner.rb:166:in `with_cop_error_handling'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/commissioner.rb:99:in `block in trigger_responding_cops'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/commissioner.rb:98:in `each'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/commissioner.rb:98:in `trigger_responding_cops'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/commissioner.rb:69:in `on_if'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:161:in `on_defs'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/commissioner.rb:71:in `on_defs'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:137:in `each'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:154:in `on_class'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/commissioner.rb:71:in `on_class'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:138:in `on_while'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/commissioner.rb:71:in `on_module'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:138:in `on_while'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/commissioner.rb:71:in `on_module'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-ast-1.4.1/lib/rubocop/ast/traversal.rb:20:in `walk'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/team.rb:157:in `investigate_partial'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cop/team.rb:83:in `investigate'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/runner.rb:315:in `inspect_file'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/runner.rb:259:in `block in do_inspection_loop'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/runner.rb:293:in `block in iterate_until_no_changes'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/runner.rb:286:in `loop'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/runner.rb:286:in `iterate_until_no_changes'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/runner.rb:255:in `do_inspection_loop'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/runner.rb:132:in `block in file_offenses'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/runner.rb:157:in `file_offense_cache'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/runner.rb:131:in `file_offenses'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/runner.rb:122:in `process_file'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/runner.rb:100:in `each'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/runner.rb:100:in `reduce'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/runner.rb:100:in `each_inspected_file'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/runner.rb:86:in `inspect_files'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/runner.rb:47:in `run'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cli.rb:65:in `run_command'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cli.rb:72:in `execute_runners'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/lib/rubocop/cli.rb:41:in `run'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/exe/rubocop:13:in `block in <top (required)>'
/Users/michaelscrivo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/benchmark.rb:308:in `realtime'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/gems/rubocop-1.11.0/exe/rubocop:12:in `<top (required)>'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/bin/rubocop:23:in `load'
/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.0.0/bin/rubocop:23:in `<top (required)>'
/Users/michaelscrivo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/cli/exec.rb:63:in `load'
/Users/michaelscrivo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/cli/exec.rb:63:in `kernel_load'
/Users/michaelscrivo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/cli/exec.rb:28:in `run'
/Users/michaelscrivo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/cli.rb:497:in `exec'
/Users/michaelscrivo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/michaelscrivo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/Users/michaelscrivo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/Users/michaelscrivo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/cli.rb:30:in `dispatch'
/Users/michaelscrivo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/Users/michaelscrivo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/cli.rb:24:in `start'
/Users/michaelscrivo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bundler-2.2.3/libexec/bundle:49:in `block in <top (required)>'
/Users/michaelscrivo/.rbenv/versions/3.0.0/lib/ruby/3.0.0/bundler/friendly_errors.rb:130:in `with_friendly_errors'
/Users/michaelscrivo/.rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/bundler-2.2.3/libexec/bundle:37:in `<top (required)>'
/Users/michaelscrivo/.rbenv/versions/3.0.0/bin/bundle:23:in `load'
/Users/michaelscrivo/.rbenv/versions/3.0.0/bin/bundle:23:in `<main>'

Steps to reproduce the problem

A class like this reproduces the issue:

module SomeModule
  class SomeClass
    def self.somemethod(params)
      if include?(Some::Other::Module)
      elsif include?(Yet::Another::Module)
      end
    end
  end
end

RuboCop version

1.11.0 (using Parser 3.0.0.0, rubocop-ast 1.4.1, running on ruby 3.0.0 x86_64-darwin20)

  • rubocop-minitest 0.10.3
  • rubocop-performance 1.10.1
  • rubocop-rake 0.5.1
@koic koic added the bug label Mar 14, 2021
koic added a commit to koic/rubocop that referenced this issue Mar 14, 2021
Fixes rubocop#9599.

This PR fixes an error for `Style/CaseLikeIf`
when using `include?` without a receiver.
koic added a commit to koic/rubocop that referenced this issue Mar 14, 2021
Fixes rubocop#9599.

This PR fixes an error for `Style/CaseLikeIf`
when using `include?` without a receiver.
koic added a commit to koic/rubocop that referenced this issue Mar 14, 2021
Fixes rubocop#9599.

This PR fixes an error for `Style/CaseLikeIf`
when using `include?` without a receiver.
koic added a commit to koic/rubocop that referenced this issue Mar 16, 2021
Fixes rubocop#9599.

This PR fixes an error for `Style/CaseLikeIf`
when using `include?` without a receiver.
bbatsov added a commit that referenced this issue Mar 16, 2021
Fixes #9599.

This PR fixes an error for `Style/CaseLikeIf`
when using `include?` without a receiver.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants