profile
viewpoint

Ask questionsRuboCop pulls in .rubocop.yml files from vendor directories

Expected behavior

Configs should not be loaded from vendor directories, which may be created automatically by CI environments like GitHub Actions.

Actual behavior

Anything in a vendor directory is processed, which causes failures when those directories are cached by CI systems like GitHub Actions.

In our case as we have a folder called kitchen-tests and inside that is a vendor dir since kitchen-tests has it's own Gemfile/Gemfile.lock. When RuboCop runs at the root of the project is ends up attempting to load a config from the vendor dir here which tries to require rubocop-discourse.

Unable to find gem rubocop-discourse; is the gem installed? Gem::MissingSpecError
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/config_loader_resolver.rb:263:in `rescue in gem_config_path'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/config_loader_resolver.rb:253:in `gem_config_path'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/config_loader_resolver.rb:69:in `block (2 levels) in resolve_inheritance_from_gems'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/config_loader_resolver.rb:67:in `reverse_each'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/config_loader_resolver.rb:67:in `block in resolve_inheritance_from_gems'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/config_loader_resolver.rb:61:in `each_pair'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/config_loader_resolver.rb:61:in `resolve_inheritance_from_gems'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/config_loader.rb:50:in `load_file'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/config_loader.rb:103:in `configuration_from_file'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/config_store.rb:68:in `for_dir'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/config_store.rb:58:in `for'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/target_finder.rb:161:in `ruby_interpreters'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/target_finder.rb:153:in `ruby_executable?'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/target_finder.rb:169:in `ruby_file?'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/target_finder.rb:73:in `to_inspect?'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/target_finder.rb:64:in `block in target_files_in_dir'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/target_finder.rb:64:in `select'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/target_finder.rb:64:in `target_files_in_dir'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/target_finder.rb:38:in `block in find'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/target_finder.rb:36:in `each'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/target_finder.rb:36:in `find'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/runner.rb:77:in `find_target_files'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/runner.rb:42:in `run'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/cli/command.rb:11:in `run'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/cli/environment.rb:18:in `run'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/cli.rb:65:in `run_command'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/cli.rb:72:in `execute_runners'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/lib/rubocop/cli.rb:41:in `run'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/exe/rubocop:12:in `block in <top (required)>'
/usr/local/Cellar/ruby@2.7/2.7.3/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/usr/local/lib/ruby/gems/2.7.0/gems/rubocop-1.15.0/exe/rubocop:12:in `<top (required)>'
/usr/local/lib/ruby/gems/2.7.0/bin/rubocop:23:in `load'
/usr/local/lib/ruby/gems/2.7.0/bin/rubocop:23:in `<main>'

That is being loaded from here

cat kitchen-tests/vendor/bundle/ruby/2.7.0/gems/mini_mime-1.1.0/.rubocop.yml
inherit_gem:
  rubocop-discourse: default.yml
inherit_mode:
  merge:
    - Exclude

Steps to reproduce the problem

Vendor a gem that includes either deprecated configs or requires a plugin and then run RuboCop.

RuboCop version

1.15.0 (using Parser 3.0.1.1, rubocop-ast 1.6.0, running on ruby 2.7.3 x86_64-darwin20)
rubocop/rubocop

Answer questions dvandersluis

Have you tried:

AllCops:
  Exclude:
  - vendor/**/*.rb # or vendor/bundle/**/*

Doing this by default for RuboCop would probably be a breaking change even though people probably shouldn't be running on code in vendor/.

useful!

Related questions

No questions were found.
source:https://uonfu.com/
answerer
Daniel Vandersluis dvandersluis Toronto, Ontario, Canada Backend Lead at Pexels. RuboCop core team member.
Github User Rank List