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

Cannot exclude vendor/ folder #288

Closed
lenntt opened this issue Jun 20, 2013 · 19 comments
Closed

Cannot exclude vendor/ folder #288

lenntt opened this issue Jun 20, 2013 · 19 comments
Assignees
Labels

Comments

@lenntt
Copy link

lenntt commented Jun 20, 2013

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?)

@ghost ghost assigned jonas054 Jun 20, 2013
@jonas054
Copy link
Collaborator

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.

@lenntt
Copy link
Author

lenntt commented Jun 20, 2013

thanks for the fast response and clearing it out

@yujinakayama
Copy link
Collaborator

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.

@lenntt lenntt closed this as completed Jun 20, 2013
@lenntt lenntt reopened this Jun 20, 2013
@lenntt
Copy link
Author

lenntt commented Jun 20, 2013

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 ;) )

@jonas054
Copy link
Collaborator

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.

@lenntt
Copy link
Author

lenntt commented Jun 20, 2013

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

@jawwad
Copy link
Contributor

jawwad commented Jul 3, 2013

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

@jonas054
Copy link
Collaborator

jonas054 commented Jul 5, 2013

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

@bogdan8
Copy link

bogdan8 commented Jul 15, 2018

@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

@jonas054
Copy link
Collaborator

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

@bogdan8
Copy link

bogdan8 commented Jul 16, 2018

@jonas054
Hi yes it helped me
Thanks)

@ianfixes
Copy link
Contributor

ianfixes commented Jan 28, 2019

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)

@dmolesUC
Copy link
Contributor

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

@marcandre
Copy link
Contributor

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.

@jonas054
Copy link
Collaborator

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.

@dmolesUC
Copy link
Contributor

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.

@philomory
Copy link

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.

@eregon
Copy link

eregon commented Dec 30, 2020

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

@eregon
Copy link

eregon commented Jan 2, 2021

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

nickcampbell18 pushed a commit to zaikio/zaikio-oauth_client that referenced this issue Apr 28, 2021
By default, this folder is excluded [issue], however when we override
the `AllCops.Exclude` option it is discarded. On CI, where we put our
gems in vendor/bundle, Rubocop was looking at all ~4492 files in those
directories and linting them. It was also parsing the .rubocop.yml files
in those directories and trying to use that configuration, leading to
this mysterious error:

  Running RuboCop...
  cannot load such file -- rubocop-rspec

(even though we do not use this library in our gem!)

By setting `inherit_mode` in .rubocop.yml, we tell it to use the default
set of exclusions, defined here: [global].

[issue]: rubocop/rubocop#288 (comment)
[global]: https://github.com/rubocop/rubocop/blob/930c812d3706a2cd647bdb20cb9c4a6d7a7ae35d/config/default.yml#L63-L67
nickcampbell18 pushed a commit to zaikio/zaikio-hub-ruby that referenced this issue Jan 4, 2022
By default, this folder is excluded [issue], however when we override
the `AllCops.Exclude` option it is discarded. On CI, where we put our
gems in vendor/bundle, Rubocop was looking at all ~4492 files in those
directories and linting them. It was also parsing the .rubocop.yml files
in those directories and trying to use that configuration, leading to
this mysterious error:

  Running RuboCop...
  cannot load such file -- rubocop-rspec

(even though we do not use this library in our gem!)

By setting `inherit_mode` in .rubocop.yml, we tell it to use the default
set of exclusions, defined here: [global].

[issue]: rubocop/rubocop#288 (comment)
[global]: https://github.com/rubocop/rubocopblob/930c812d3706a2cd647bdb20cb9c4a6d7a7ae35d/config/default.yml#L63-L67/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests