Rubocop: Cannot exclude vendor/ folder

Created on 20 Jun 2013  ยท  19Comments  ยท  Source: rubocop-hq/rubocop

I'm using bundler, and all my gems are installed in projects_folder/vendor/ (including rubocop).
I've been succesfully excluding folders, but somehow I'm not able to exclude the vendor folder. Maybe it has something to do with rubocop being in it???

I think I've tried everything, like

vendor/**
'**/vendor/**'
vendor/**/*

etc.

(furthermore: in the code in Rubocop::Config#match_path? I see that pattern can either be a string or a regex... but how to define a regex in the rubocop.yml?)

bug

Most helpful comment

@bogdan8 Yes, the correct pattern for excluding all files under vendor recursively is vendor/**/*.

All 19 comments

It looks like we have a bug, and it affects regexp as well as glob pattern matching. You can find the syntax for ruby regular expressions in YAML here, but it won't help you circumvent the bug.

I will investigate further.

thanks for the fast response and clearing it out

I guess this is a situation like below:

.
โ”œโ”€โ”€ .rubocop.yml # config-A: this tries to exclude `vendor`
โ”œโ”€โ”€ Gemfile
โ”œโ”€โ”€ lib
โ”‚ย ย  โ””โ”€โ”€ foo.rb
โ””โ”€โ”€ vendor
    โ””โ”€โ”€ bundle
        โ””โ”€โ”€ ruby
            โ””โ”€โ”€ 2.0.0
                โ”œโ”€โ”€ gems
                โ”‚ย ย  โ”œโ”€โ”€ rubocop-0.8.3
                โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ .rubocop.yml # config-B: this does not inherit config-A
                โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ lib
                โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ rubocop
                โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ cli.rb # RuboCop refers only config-B when inspecting this file
...

I think this is an issue with the configuration loading design rather than bug.

sorry for closing and reopening, pressed the wrong button.

I think the scenario sketched by @yujinakayama is correct.
(Though my definition of a bug may differ a little ;) )

Very clear explanation @yujinakayama. I hadn't thought about this problem before, but now when I do, I want to call it a bug. It should be possible to exclude everything under vendor from config-A.

@SirLenz0rlot Did you have any other gems under vendor? Were they excluded? I think there may be two different problems that come into play here.

@jonas054 Yes, all my gems are under vendor/bundle (except for e.g. bundler). I tried to exclude the entire vendor folder.

I'm seeing some weird behavior on this...
I have vendor/** under Excludes: in my .rubocop.yml file.
While it does exclude files from vendor, it still ends up checking files in vendor/bundle/ruby/1.9.1/gems/parser-2.0.0.beta9

However it does exclude properly if I run rubocop this way...
rubocop --config .rubocop.yml

> rubocop
Inspecting 1043 files

> rubocop --config .rubocop.yml
Inspecting 765 files

It seems we still have a bug. Thanks for reporting. I'm reopening the issue and will start to investigate.

@jonas054
Hi, I launch a rubocop through a Travise in the github
but for some reason it checks the folder vendore Maybe you know why?

Travis:

script: bundle exec rspec spec && bundle exec rubocop --config .rubocop.yml

.rubocop.yml

AllCops:
  DisplayStyleGuide: true
  DisplayCopNames: true
  Include:
    - '**/Gemfile'
    - '**/Rakefile'
  Exclude:
    - '**/bin/spring'
    - '**/bin/setup'
    - '**/bin/rake'
    - '**/bin/rails'
    - '**/db/schema.rb'
    - 'client/**/**'
    - 'config/**/**'
    - 'db/**/**'
    - 'bin/**'
    - 'app/models/role.rb'
    - 'vendor/*'
Rails:
  Enabled: true

Metrics/LineLength:
  Max: 120

Metrics/MethodLength:
  Max: 20

Style/Documentation:
  Enabled: false

Metrics/AbcSize:
  Max: 25

Metrics/ModuleLength:
  Exclude:
    - "**/*_spec.rb"

Metrics/BlockLength:
  Exclude:
    - "**/*_spec.rb"
  ExcludedMethods: ['included']

screenshot from 2018-07-15 15-37-06

@bogdan8 Yes, the correct pattern for excluding all files under vendor recursively is vendor/**/*.

@jonas054
Hi yes it helped me
Thanks)

I stumbled on this while looking for a way to ask the bundler where it's storing the dependencies -- that way, I could avoid doing _any_ work on files under that directory.

I ended up going with a more brute-force solution based on bundle show --paths, but I'd be glad to learn of a better way: https://github.com/Arduino-CI/arduino_ci/pull/98/files#diff-628053b8ae99f228ce5db85a0bd2a145R63

(This function is probably of more use to the RuboCop maintainers than the consumers of the gem)

Is there a reason why vendor is not excluded by default?

Is there a reason why vendor is not excluded by default?

I agree it probably should. I'll try to remember to do that when I tackle #7819; you may want to subscribe to that thread.

It _is_ excluded by default. What happened here was that AllCops: Exclude was overridden in the local .rubocop.yml, so then you need to either set inherit_mode or copy the patterns you need to the local AllCops: Exclude.

OK, I've been using RuboCop for six years and this is the first time I've heard of inherit_mode โ€”ย I see it wasn't in the README back in the day.

Personally I think Exclude should default to merge, but failing that, maybe it should be documented more prominently -- or the fact that without it adding any custom Exclude will lose the defaults should be called out more explicitly. Given the special behavior of Include and Exclude with regard to shadowing in subdirectories, it's not entirely intuitive.

I have to agree with @dmolesUC ; it's pretty surprising to _add_ an exclude directive to .rubocop.yml and have that result in files that were previous being excluded no longer being so. It's true that after reading about it and reasoning about it you can totally understand how it works, but it's pretty confusing when you first encounter it.

:+1: on merging Exclude: should be the default, who doesn't want that?

I filed an issue to merge Exclude: by default, I believe that is always the intention for RuboCop users: #9325

Was this page helpful?
0 / 5 - 0 ratings