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
Comments
Hello, wanted to check in and see if there was any traction on this? Thanks! |
@buehmann I was just hit with the same problem. Have you find a better solution for this problem?
|
@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. 😢 |
Thank you for letting me know @bkuhlmann . |
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. |
🙇 @deivid-rodriguez, that'd be awesome and would better support the work behind the splitting of Rubocop into smaller projects. |
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 So, for example, with ---
AllCops:
DisabledByDefault: true
Style/StringLiterals:
EnforcedStyle: double_quotes And a project ---
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
The problem seems related to |
@deivid-rodriguez, if it helps, I can generate the same error regardless of whether 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. |
What's the error when running with the |
Confirmed that you get the same kind of error and information about
|
And the 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. |
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
|
I created #8176 to try fix this. |
🙇 @deivid-rodriguez. Just got back from lunch and catching up -- Sorry, I wasn't around to catch the |
No problem, I'm happy it fixes your issue too! |
…_if_project_present [Fix #7433] User vs project exclusion inheritance
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:
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):
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)
The text was updated successfully, but these errors were encountered: