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 requires its own .rubocop.yml to exist to function correctly #557

Closed
Confusion opened this issue Oct 10, 2013 · 10 comments
Closed

Comments

@Confusion
Copy link

A colleague of mine just upgraded one of our projects to rubocop-0.14.0. After git pull and bundle install, I get the following error when running bundle exec rake rubocop

rubocop --format progress
No such file or directory - $PROJECT/vendor/bundle/ruby/1.9.1/gems/rubocop-0.14.0/.rubocop.yml

This file indeed does not exist, although it is present in the .gem file. The gem was installed using rubygems 2.1.5 and bundler 1.3.4.

Now not installing that file may be a bug or feature of either rubygems or bundler, but regardless of that, it seems strange that rubocop requires a local .rubocop.yml in the directory where it was installed to function properly. There is a .rubocop.yml present at the $PROJECT level, which is the one that should be used. Is this a bug?

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 10, 2013

The rubocop.yml in RuboCop's source code simply contains the project specific settings; it's definitely not required for RuboCop to work. Not sure what exactly is the problem, though. I guess @jonas054 will check it out at some point, since he's in the charge of the config issues.

@yujinakayama
Copy link
Collaborator

I think that's because $PROJECT/vendor/bundle/ruby/1.9.1/gems/rubocop-0.14.0/spec/.rubocop.yml contains inherit_from: ../.rubocop.yml.

@jonas054
Copy link
Collaborator

That seems likely, @yujinakayama. The problem is that vendor/bundle/ruby/1.9.1/gems/rubocop-0.14.0/.rubocop.yml is missing, and rubocop is behaving as expected.

@Confusion
Copy link
Author

What is vendor/bundle/ruby/1.9.1/gems/rubocop-0.14.0/.rubocop.yml used for when I invoke the rubocop rake task to check my own code?

@jonas054
Copy link
Collaborator

In the end it's not used for anything (assuming you have excluded the vendor directory in the project's .rubocop.yml), but RuboCop doesn't know that when it resolves the chain of configuration files. The algorithm is basically like this:

  1. Find files recursively
  2. Associate each file with its configuration
  3. For each file, see if its configuration says that it shall be excluded
  4. Inspect the files that have not been excluded

More details and a discussion about why RuboCop works like this can be found in #536.

@Confusion
Copy link
Author

I dug into the problem and it's an issue with rubygems that has existed since their version 2.1.0 (2.0.11 works fine). It simply doesn't install files starting with a period. I filed rubygems/rubygems#680 with them. I expect more people will be having this problem when using rubocop with a recent rubygems.

(why am I using a version of rubygems different from my colleague? Because I was testing upgrades :))

@jonas054
Copy link
Collaborator

That's too bad, but it's good that you found the problem, @Confusion.

Partly because of this bug in rubygems, and partly because we seem to get a new bug report to RuboCop every other week about its behavior regarding exclusion of vendor directories, I think it's time to make some changes. I know @yujinakayama has mentioned that he has some ideas for a redesign of the configuration functionality. I have an idea for a smaller change that I want to make first. It's basically that we move the exclusion of files earlier in TargetFinder's algorithm. I'll try to submit a PR pretty soon.

@lenntt
Copy link

lenntt commented Oct 11, 2013

I haven't checked out the fix yet, but I guess its also supposed to fix this scenario:

When I'm using my project with 2 different rubies and 2 different versions of Rubocop (ok uncommon scenario, but it signals rubocop is doing something unexpected. Lets say ruby 1.9.3 uses rubocop 0.14.0 and ruby 2.0 uses 0.10.0.
This means I've got a vendor/bundle/ruby/2.0.0 and a vendor/bundle/ruby/1.9.1.

When Im running rubocop under ruby 1.9.3, rubocop warns me several times:

Warning: unrecognized cop SpaceAroundBraces found in <path>/vendor/bundle/ruby/2.0.0/gems/rubocop-0.10.0/config/enabled.yml
Warning: unrecognized cop SpaceAroundBraces found in <path>/vendor/bundle/ruby/2.0.0/gems/rubocop-0.10.0/config/default.yml
Warning: unrecognized cop SpaceAroundBraces found in<path>/vendor/bundle/ruby/2.0.0/gems/rubocop-0.10.0/.rubocop.yml
Warning: unrecognized cop SpaceAroundBraces found in <path>/vendor/bundle/ruby/2.0.0/gems/rubocop-0.10.0/config/enabled.yml
Warning: unrecognized cop SpaceAroundBraces found in<path>/vendor/bundle/ruby/2.0.0/gems/rubocop-0.10.0/config/default.yml
Warning: unrecognized cop SpaceAroundBraces found in <path>/vendor/bundle/ruby/2.0.0/gems/rubocop-0.10.0/.rubocop.yml
Warning: unrecognized cop SpaceAroundBraces found in /<path>/vendor/bundle/ruby/2.0.0/gems/rubocop-0.10.0/spec/.rubocop.yml

bbatsov added a commit that referenced this issue Oct 11, 2013
[Fix #557] Don't load configuration files for excluded files.
@jonas054
Copy link
Collaborator

Yes @SirLenz0rlot that scenario should also be fixed. As long as you have the vendor directory excluded, RuboCop should not open any configuration files under it.

@lenntt
Copy link

lenntt commented Oct 11, 2013

Thanks for pointing that out (and the fix ofcourse). I'll check the fix later when the gem is released.

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

5 participants