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

Fix inherit_from issue with global configuration #7433

Closed
bkuhlmann opened this issue Oct 15, 2019 · 15 comments
Closed

Fix inherit_from issue with global configuration #7433

bkuhlmann opened this issue Oct 15, 2019 · 15 comments

Comments

@bkuhlmann
Copy link

bkuhlmann commented Oct 15, 2019

Expected behavior

Would expect Rubocop to honor the project specific directive for inherit_from instead of the global configuration of the entire system. For example, here's my setup:

Actual behavior

When running Rubocop within the Benchmarks project, I get the following stack dump:

cannot load such file -- rubocop-performance
/Users/bkuhlmann/.rubies/ruby-2.6.5/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/bkuhlmann/.rubies/ruby-2.6.5/lib/ruby/site_ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/Users/bkuhlmann/.gem/ruby/2.6.5/gems/rubocop-0.75.1/lib/rubocop/config_loader_resolver.rb:15:in `block in resolve_requires'
/Users/bkuhlmann/.gem/ruby/2.6.5/gems/rubocop-0.75.1/lib/rubocop/config_loader_resolver.rb:11:in `each'
/Users/bkuhlmann/.gem/ruby/2.6.5/gems/rubocop-0.75.1/lib/rubocop/config_loader_resolver.rb:11:in `resolve_requires'
/Users/bkuhlmann/.gem/ruby/2.6.5/gems/rubocop-0.75.1/lib/rubocop/config_loader.rb:45:in `load_file'
/Users/bkuhlmann/.gem/ruby/2.6.5/gems/rubocop-0.75.1/lib/rubocop/config_loader_resolver.rb:142:in `block in base_configs'
/Users/bkuhlmann/.gem/ruby/2.6.5/gems/rubocop-0.75.1/lib/rubocop/config_loader_resolver.rb:141:in `map'
/Users/bkuhlmann/.gem/ruby/2.6.5/gems/rubocop-0.75.1/lib/rubocop/config_loader_resolver.rb:141:in `base_configs'
/Users/bkuhlmann/.gem/ruby/2.6.5/gems/rubocop-0.75.1/lib/rubocop/config_loader_resolver.rb:22:in `resolve_inheritance'
/Users/bkuhlmann/.gem/ruby/2.6.5/gems/rubocop-0.75.1/lib/rubocop/config_loader.rb:50:in `load_file'
/Users/bkuhlmann/.gem/ruby/2.6.5/gems/rubocop-0.75.1/lib/rubocop/config_loader.rb:107:in `add_excludes_from_files'
/Users/bkuhlmann/.gem/ruby/2.6.5/gems/rubocop-0.75.1/lib/rubocop/config_loader.rb:92:in `configuration_from_file'
/Users/bkuhlmann/.gem/ruby/2.6.5/gems/rubocop-0.75.1/lib/rubocop/config_store.rb:44:in `for'
/Users/bkuhlmann/.gem/ruby/2.6.5/gems/rubocop-0.75.1/lib/rubocop/cli.rb:180:in `validate_options_vs_config'
/Users/bkuhlmann/.gem/ruby/2.6.5/gems/rubocop-0.75.1/lib/rubocop/cli.rb:48:in `run'
/Users/bkuhlmann/.gem/ruby/2.6.5/gems/rubocop-0.75.1/exe/rubocop:13:in `block in <top (required)>'
/Users/bkuhlmann/.rubies/ruby-2.6.5/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
/Users/bkuhlmann/.gem/ruby/2.6.5/gems/rubocop-0.75.1/exe/rubocop:12:in `<top (required)>'
/Users/bkuhlmann/.gem/ruby/2.6.5/bin/rubocop:23:in `load'
/Users/bkuhlmann/.gem/ruby/2.6.5/bin/rubocop:23:in `<main>'

Again, notice how Rubocop Performance gem is attempting to be required here due to my global Dotfiles configuration requiring it but is definitely not required by my Benchmarks project.

Steps to reproduce the problem

You should be able to reproduce this via the following steps (:warning: Ensure you backup your global configuration first, if you have one, before proceeding):

curl --location --fail --show-error "https://github.com/bkuhlmann/dotfiles/blob/master/home_files/.config/rubocop/config.yml.tt" > "$HOME/.config/rubocop/config.yml"
git clone https://github.com/bkuhlmann/benchmarks.git
cd benchmarks
bundle exec rubocop

Workaround

I've been able to temporarily resolve this situation by using direnv and adding this code to my local, Benchmarks, project .envrc

export XDG_CONFIG_HOME=/dev/null

Doing this ensures the global Rubocop configuration from my Dotfiles are not loaded.

RuboCop version

0.75.1 (using Parser 2.6.5.0, running on ruby 2.6.5 x86_64-darwin18)

@bkuhlmann
Copy link
Author

Hello, wanted to check in and see if there was any traction on this? Thanks!

@victormartins
Copy link

@buehmann I was just hit with the same problem.
If I try to satisfy the rubocop-performance dependency by adding them to the Gemfile it keeps requesting additional gems like rubocop-rails and rubocop-rspec ...

Have you find a better solution for this problem?
Thank you.

cannot load such file -- rubocop-performance
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/config_loader_resolver.rb:15:in `require'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/config_loader_resolver.rb:15:in `block in resolve_requires'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/config_loader_resolver.rb:11:in `each'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/config_loader_resolver.rb:11:in `resolve_requires'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/config_loader.rb:45:in `load_file'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/config_loader.rb:89:in `configuration_from_file'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/config_store.rb:44:in `for'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/cli.rb:126:in `apply_default_formatter'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/lib/rubocop/cli.rb:40:in `run'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/exe/rubocop:13:in `block in <top (required)>'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/benchmark-0.1.0/lib/benchmark.rb:308:in `realtime'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/rubocop-0.82.0/exe/rubocop:12:in `<top (required)>'
/Users/victor.martins/.rbenv/versions/2.6.4/bin/rubocop:23:in `load'
/Users/victor.martins/.rbenv/versions/2.6.4/bin/rubocop:23:in `<top (required)>'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/Users/victor.martins/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
/Users/victor.martins/.rbenv/versions/2.6.4/bin/bundle:23:in `load'
/Users/victor.martins/.rbenv/versions/2.6.4/bin/bundle:23:in `<main>'

@bkuhlmann
Copy link
Author

@victormartins I'm afraid I don't have a better workaround other than what I posted originally. The direnv workaround sort of works but isn't great. 😢

@victormartins
Copy link

Thank you for letting me know @bkuhlmann .

@deivid-rodriguez
Copy link
Contributor

deivid-rodriguez commented Jun 20, 2020

I keep running into this issue too :(

I opened a very similar ticket at #7017, but I closed it because from reading the docs, it seemed like expected behaviour.

Still, I don't think how the current behaviour can be useful, so I consider this an issue.

If this is acknowledged as a problem, I'm happy to try work on it.

@bkuhlmann
Copy link
Author

🙇 @deivid-rodriguez, that'd be awesome and would better support the work behind the splitting of Rubocop into smaller projects.

@deivid-rodriguez
Copy link
Contributor

deivid-rodriguez commented Jun 20, 2020

I'm digging a bit more into it. Actually the behaviour I was requesting in #7017 seems there, that's ok 👍. But the "user configuration" seems still read sometimes even if there's a project .rubocop.yml. And the fact that the configuration is actually loaded messes up things like require: or inherit_from:.

So, for example, with ~/.rubocop.yml like this:

---

AllCops:
  DisabledByDefault: true

Style/StringLiterals:
  EnforcedStyle: double_quotes

And a project ./.rubocop.yml like this:

---

AllCops:
  TargetRubyVersion: 2.4

Everything looks good. User configuration is ignored: all cops run, and single quotes are enforced.

However, if we add something like require: rubocop-performance to the user configuration, the rubocop starts crashing:

For /home/deivid/Code/simplecov: configuration from /home/deivid/Code/simplecov/.rubocop.yml
Default configuration from /home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/config/default.yml
AllCops/Exclude configuration from /home/deivid/.rubocop.yml
cannot load such file -- rubocop-performance
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader_resolver.rb:15:in `require'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader_resolver.rb:15:in `block in resolve_requires'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader_resolver.rb:11:in `each'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader_resolver.rb:11:in `resolve_requires'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader.rb:45:in `load_file'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader.rb:116:in `add_excludes_from_files'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader.rb:94:in `configuration_from_file'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_store.rb:54:in `for_dir'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/cli.rb:126:in `apply_default_formatter'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/lib/rubocop/cli.rb:40:in `run'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/exe/rubocop:13:in `block in <top (required)>'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.85.1/exe/rubocop:12:in `<top (required)>'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bin/rubocop:23:in `load'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/bin/rubocop:23:in `<top (required)>'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/cli/exec.rb:63:in `load'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/cli/exec.rb:63:in `kernel_load'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/cli/exec.rb:28:in `run'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/cli.rb:481:in `exec'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/cli.rb:30:in `dispatch'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/cli.rb:24:in `start'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.2.0.dev/exe/bundle:49:in `block in <top (required)>'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/friendly_errors.rb:117:in `with_friendly_errors'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.2.0.dev/exe/bundle:37:in `<top (required)>'
/home/deivid/.rbenv/versions/2.7.1/bin/bundle:23:in `load'
/home/deivid/.rbenv/versions/2.7.1/bin/bundle:23:in `<main>'
Finished in 0.07059375099925091 seconds

The problem seems related to AllCops/Exclude inheritance that it's still loading ~/.rubocop.yml even if it should be completely ignored?

@bkuhlmann
Copy link
Author

@deivid-rodriguez, if it helps, I can generate the same error regardless of whether AllCops is defined at the global level or not. I also tried deleting my AllCops configuration from that file and the error persisted. The root cause seems to stem from the inherit_from directive. For example:

Dotfiles (global example)

inherit_from:
  - https://raw.githubusercontent.com/bkuhlmann/code_quality/master/configurations/rubocop/ruby.yml
  - https://raw.githubusercontent.com/bkuhlmann/code_quality/master/configurations/rubocop/rake.yml
  - https://raw.githubusercontent.com/bkuhlmann/code_quality/master/configurations/rubocop/performance.yml
  - https://raw.githubusercontent.com/bkuhlmann/code_quality/master/configurations/rubocop/rspec.yml

Benchmarks (project specific example)

inherit_from:
  - https://raw.githubusercontent.com/bkuhlmann/code_quality/master/configurations/rubocop/ruby.yml
  - https://raw.githubusercontent.com/bkuhlmann/code_quality/master/configurations/rubocop/rake.yml
  - https://raw.githubusercontent.com/bkuhlmann/code_quality/master/configurations/rubocop/rspec.yml

I would expect the local Benchmarks example to only inherit from the ruby, rake, and rspec configuration. Unfortunately, the global Dotfiles configuration overrides the Benchmarks configuration and pulls in ruby, rake, rspec, and the performance configuration -- which is what causes the stack dump because the RSpec Performance gem isn't required for the Benchmarks project. 😢

It might be that the global configuration isn't an override but maybe it's an array union of both the original global configuration and project specific configuration. Not sure.

@deivid-rodriguez
Copy link
Contributor

What's the error when running with the --debug flag?

@deivid-rodriguez
Copy link
Contributor

Confirmed that you get the same kind of error and information about AllCops/Exclude being read from ~/.rubocop.yml (even if there's none).

For /home/deivid/Code/playground: configuration from /home/deivid/Code/playground/.rubocop.yml
configuration from /home/deivid/Code/playground/.rubocop-https---raw-githubusercontent-com-bkuhlmann-code-quality-master-configurations-rubocop-ruby-yml
Default configuration from /home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/config/default.yml
configuration from /home/deivid/Code/playground/.rubocop-https---raw-githubusercontent-com-bkuhlmann-code-quality-master-configurations-rubocop-rake-yml
configuration from /home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-rake-0.5.1/config/default.yml
configuration from /home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-rake-0.5.1/config/default.yml
configuration from /home/deivid/Code/playground/.rubocop-https---raw-githubusercontent-com-bkuhlmann-code-quality-master-configurations-rubocop-rspec-yml
configuration from /home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-rspec-1.40.0/config/default.yml
configuration from /home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-rspec-1.40.0/config/default.yml
AllCops/Exclude configuration from /home/deivid/.rubocop.yml
configuration from /home/deivid/.rubocop-https---raw-githubusercontent-com-bkuhlmann-code-quality-master-configurations-rubocop-ruby-yml
configuration from /home/deivid/.rubocop-https---raw-githubusercontent-com-bkuhlmann-code-quality-master-configurations-rubocop-rake-yml
configuration from /home/deivid/.rubocop-https---raw-githubusercontent-com-bkuhlmann-code-quality-master-configurations-rubocop-performance-yml
cannot load such file -- rubocop-performance
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader_resolver.rb:15:in `require'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader_resolver.rb:15:in `block in resolve_requires'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader_resolver.rb:11:in `each'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader_resolver.rb:11:in `resolve_requires'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader.rb:45:in `load_file'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader_resolver.rb:166:in `block in base_configs'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader_resolver.rb:165:in `map'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader_resolver.rb:165:in `base_configs'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader_resolver.rb:23:in `resolve_inheritance'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader.rb:51:in `load_file'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader.rb:116:in `add_excludes_from_files'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_loader.rb:94:in `configuration_from_file'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/lib/rubocop/config_store.rb:54:in `for_dir'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/lib/rubocop/cli.rb:126:in `apply_default_formatter'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/lib/rubocop/cli.rb:40:in `run'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/exe/rubocop:13:in `block in <top (required)>'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/gems/rubocop-0.85.1/exe/rubocop:12:in `<top (required)>'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/bin/rubocop:23:in `load'
/home/deivid/Code/playground/vendor/bundle/ruby/2.7.0/bin/rubocop:23:in `<top (required)>'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/cli/exec.rb:63:in `load'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/cli/exec.rb:63:in `kernel_load'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/cli/exec.rb:28:in `run'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/cli.rb:481:in `exec'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/cli.rb:30:in `dispatch'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/cli.rb:24:in `start'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.2.0.dev/exe/bundle:49:in `block in <top (required)>'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/site_ruby/2.7.0/bundler/friendly_errors.rb:117:in `with_friendly_errors'
/home/deivid/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bundler-2.2.0.dev/exe/bundle:37:in `<top (required)>'
/home/deivid/.rbenv/versions/2.7.1/bin/bundle:23:in `load'
/home/deivid/.rbenv/versions/2.7.1/bin/bundle:23:in `<main>'
Finished in 0.84597394299999 seconds

@deivid-rodriguez
Copy link
Contributor

And the --ignore-parent-exclusion flag workarounds the issue.

So in my opinion the problem is that "directory traversal" for parent exclusions is going "too high". It should stop at the root of the project.

@deivid-rodriguez
Copy link
Contributor

deivid-rodriguez commented Jun 20, 2020

The following patch fixes things for me and doesn't seem to break any specs, so sounds promising.

diff --git a/lib/rubocop/config_loader.rb b/lib/rubocop/config_loader.rb
index c0a1661b9..21892c7af 100644
--- a/lib/rubocop/config_loader.rb
+++ b/lib/rubocop/config_loader.rb
@@ -105,8 +105,7 @@ module RuboCop
       end
 
       def add_excludes_from_files(config, config_file)
-        found_files = find_files_upwards(DOTFILE, config_file) +
-                      [find_user_dotfile, find_user_xdg_config].compact
+        found_files = find_files_upwards(DOTFILE, config_file)
 
         return if found_files.empty?
         return if PathUtil.relative_path(found_files.last) ==
diff --git a/lib/rubocop/file_finder.rb b/lib/rubocop/file_finder.rb
index ed0c16eea..4ab87f122 100644
--- a/lib/rubocop/file_finder.rb
+++ b/lib/rubocop/file_finder.rb
@@ -10,6 +10,8 @@ module RuboCop
     end
 
     def self.root_level?(path)
+      @root_level ||= File.dirname(Dir.pwd)
+
       @root_level == path.to_s
     end
 

@deivid-rodriguez
Copy link
Contributor

I created #8176 to try fix this.

@bkuhlmann
Copy link
Author

bkuhlmann commented Jun 20, 2020

🙇 @deivid-rodriguez. Just got back from lunch and catching up -- Sorry, I wasn't around to catch the --debug question earlier. I applied your patch, locally, and this resolves the issue for me as well. 🎉

@deivid-rodriguez
Copy link
Contributor

No problem, I'm happy it fixes your issue too!

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

3 participants