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

undefined method `gem_dir' for nil:NilClass when running the rubocop command on 0.35.0 #2411

Closed
roberts1000 opened this issue Nov 9, 2015 · 3 comments

Comments

@roberts1000
Copy link
Contributor

I just upgraded from 0.34.2 to 0.35.0. I'm using the inherit_gem functionality, but I'm getting this error.

undefined method `gem_dir' for nil:NilClass
/home/user/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.0/lib/rubocop/config_loader.rb:184:in `gem_config_path'
/home/user/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.0/lib/rubocop/config_loader.rb:178:in `block in resolve_inheritance_from_gems'
/home/user/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.0/lib/rubocop/config_loader.rb:176:in `each_pair'
/home/user/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.0/lib/rubocop/config_loader.rb:176:in `resolve_inheritance_from_gems'
/home/user/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.0/lib/rubocop/config_loader.rb:30:in `load_file'
/home/user/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.0/lib/rubocop/config_loader.rb:92:in `configuration_from_file'
/home/user/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.0/lib/rubocop/config_store.rb:40:in `for'
/home/user/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.0/lib/rubocop/target_finder.rb:112:in `excluded_dirs'
/home/user/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.0/lib/rubocop/target_finder.rb:90:in `find_files'
/home/user/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.0/lib/rubocop/target_finder.rb:60:in `target_files_in_dir'
/home/user/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.0/lib/rubocop/target_finder.rb:31:in `find'
/home/user/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.0/lib/rubocop/runner.rb:46:in `find_target_files'
/home/user/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.0/lib/rubocop/runner.rb:30:in `run'
/home/user/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.0/lib/rubocop/cli.rb:26:in `run'
/home/user/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.0/bin/rubocop:13:in `block in <top (required)>'
/home/user/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
/home/user/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.0/bin/rubocop:12:in `<top (required)>'
/home/user/.rvm/gems/ruby-2.2.3/bin/rubocop:23:in `load'
/home/user/.rvm/gems/ruby-2.2.3/bin/rubocop:23:in `<main>'
/home/user/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `eval'
/home/user/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `<main>'

The .rubocop.yml in my application has:

inherit_gem:
  rubocop: config/default.yml
  my_gem: config/.rubocop.yml

Here is what I have observed:

  1. If I take the .rubocop.yml out of the gem and overwrite the .rubocop.yml in the application (a.k.a don't load .rubocop.yml from my_gem or use inherit_gem), then rubocop works fine.
  2. If I downgrade rubocop and to 0.34.2, and try to use inherit_gem, I get a message about "unrecognized cop inherit_gem".
  3. Prior to the release of rubocop 0.35.0, we were loading rubocop HEAD via the :git option in our application's Gemfile. This worked locally; we were able to use the inherit_gem functionality in development. However, our CI pipeline would generate errors during a deploy. We eventually traced it back to "something" with rubocop. If we stopped using :git and just used rubocop 0.34.2 without inherit_gem then our CI deployments worked fine.
  4. In my application Gemfile, if I load my_gem via the :path option, the inherit_gem functionality works fine. On my local development machine, I'm able to use inherit_gem to pull the .rubocop.yml out of my_gem. As soon as I drop the :path option in the application's Gemfile, I get the above error.

my_gem doesn't do anything crazy. It's a very simple gem that just holds config/.rubocop.yml file and it installs an executable named rubo which executes the rubocop with specific options so we can have a simple standard command for our team.

@jonas054
Copy link
Collaborator

I'm not sure why you get that nilreference and I haven't been able to reproduce it, but either way you should not explicitly inherit from RuboCop's config/default.yml. All configurations are implicitly based on the config/default.yml of the rubocop being run.

@roberts1000
Copy link
Contributor Author

Thanks for taking a look. I'll do some deeper debugging on my end and see if I can come up with some more specific.

I included config/default.yml because the README section on inherit_gem showed this snippet of code:

inherit_gem:
  rubocop: config/default.yml
  my-shared-gem: .rubocop.yml
  cucumber: conf/rubocop.yml

I thought that mean config/default.yml was needed as a base when using inherit_gem. Thanks for the tip.

jonas054 added a commit to jonas054/rubocop that referenced this issue Nov 11, 2015
The problem was discovered in rubocop#2411, but this change does not
fix the problem reported there.

Make configuration loading work as described in the README regarding
precedence of `.rubocop.yml`, `inherit_from`, and `inherit_gem`.

Remove `rubocop: config/default.yml` from the example in the
README as it makes no sense. All configurations are based on the
`default.yml` of the `rubocop` being run.
@alexdowad
Copy link
Contributor

@roberts1000 Do you still have the same problem after removing config/default.yml?

@bbatsov bbatsov closed this as completed Dec 25, 2015
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

4 participants