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

Rubocop errors with "private method `select' called for nil:NilClass" #1867

Closed
jmromer opened this issue May 5, 2015 · 2 comments · Fixed by #12032
Closed

Rubocop errors with "private method `select' called for nil:NilClass" #1867

jmromer opened this issue May 5, 2015 · 2 comments · Fixed by #12032

Comments

@jmromer
Copy link

jmromer commented May 5, 2015

I'm getting some error messages on Ruby 2.1.6.


% rubocop config/routes.rb
Inspecting 1 file
An error occurred while Style/FileName cop was inspecting ~/Desktop/project/config/routes.rb.
To see the complete backtrace run rubocop -d.
C

[. . . ]

1 error occurred:

An error occurred while Style/FileName cop was inspecting ~/Desktop/project/config/routes.rb.

Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
Mention the following information in the issue report:
0.31.0 (using Parser 2.2.2.2, running on ruby 2.1.6 x86_64-darwin14.0)
% rubocop -d

For ~/Desktop/project: configuration from ~/.rubocop.yml
Default configuration from ~/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rubocop-0.31.0/config/default.yml
Inheriting configuration from ~/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rubocop-0.31.0/config/enabled.yml
Inheriting configuration from ~/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rubocop-0.31.0/config/disabled.yml

private method 'select' called for nil:NilClass
~/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rubocop-0.31.0/lib/rubocop/target_finder.rb:113:in 'excluded_dirs'
~/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rubocop-0.31.0/lib/rubocop/target_finder.rb:90:in 'find_files'
~/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rubocop-0.31.0/lib/rubocop/target_finder.rb:60:in 'target_files_in_dir'
~/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rubocop-0.31.0/lib/rubocop/target_finder.rb:31:in 'find'
~/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rubocop-0.31.0/lib/rubocop/runner.rb:41:in 'find_target_files'
~/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rubocop-0.31.0/lib/rubocop/runner.rb:29:in 'run'
~/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rubocop-0.31.0/lib/rubocop/cli.rb:26:in 'run'
~/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rubocop-0.31.0/bin/rubocop:13:in 'block in <top (required)>'
~/.rbenv/versions/2.1.6/lib/ruby/2.1.0/benchmark.rb:294:in 'realtime'
~/.rbenv/versions/2.1.6/lib/ruby/gems/2.1.0/gems/rubocop-0.31.0/bin/rubocop:12:in '<top (required)>'
~/.rbenv/versions/2.1.6/bin/rubocop:23:in 'load'
~/.rbenv/versions/2.1.6/bin/rubocop:23:in '<main>'
~/.rbenv/versions/2.1.6/bin/ruby_executable_hooks:15:in 'eval'
~/.rbenv/versions/2.1.6/bin/ruby_executable_hooks:15:in '<main>'
Finished in 0.018387 seconds


@jmromer jmromer changed the title Rubocop fails with "private method `select' called for nil:NilClass" Rubocop errors with "private method `select' called for nil:NilClass" May 5, 2015
@jmromer
Copy link
Author

jmromer commented May 5, 2015

This was caused by overriding Exclude incorrectly in my local .rubocop.yml:

AllCops:
  Exclude:

Fixed by deleting the Exclude: line.

@jmromer jmromer closed this as completed May 5, 2015
@AlexWayfer
Copy link
Contributor

I've got this error in CI.

My AllCops config is:

AllCops:
  NewCops: enable
  Exclude:
    <% `git status --ignored --porcelain`.lines.grep(/^!! /).each do |path| %>
      - <%= path.sub(/^!! /, '') %>
    <% end %>

So, it's not "empty", but I guess the command can return zero entries.

Locally it works:

> git status --ignored --porcelain
 M .gitignore
!! config/database.yaml
!! config/deploy.yaml
!! config/logging.yaml
!! config/main.yaml
!! config/systemd.service
!! db/
!! node_modules/
!! package-lock.json

But it's a dynamic list, and in CI there are no such files (they're not required for RuboCop), and I guess I have to wrap Exclude: into something like <% if ENV['CI'] %>.

koic added a commit to koic/rubocop that referenced this issue Jul 6, 2023
…ubocop.yml

Fixes rubocop#1867.

This PR fixes the following error when `AllCops:Exclude` is empty in .rubocop.yml.

```console
$ cat .rubocop.yml
AllCops:
  Exclude:

$ rubocop
(snip)

private method `select' called for nil
/Users/koic/.rbenv/versions/3.3.0-dev/lib/ruby/gems/3.3.0+0/gems/rubocop-1.54.1/lib/rubocop/target_finder.rb:118:
in `combined_exclude_glob_patterns'
/Users/koic/.rbenv/versions/3.3.0-dev/lib/ruby/gems/3.3.0+0/gems/rubocop-1.54.1/lib/rubocop/target_finder.rb:85:
in `find_files'
/Users/koic/.rbenv/versions/3.3.0-dev/lib/ruby/gems/3.3.0+0/gems/rubocop-1.54.1/lib/rubocop/target_finder.rb:59:
in `target_files_in_dir'
```
koic added a commit that referenced this issue Jul 8, 2023
…_is_empty

[Fix #1867] Fix an error when `AllCops:Exclude` is empty in .rubocop.yml
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.

2 participants