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
Don't load configuration files outside of the current project unless there's no project specific configuration #8314
Merged
bbatsov
merged 4 commits into
rubocop:master
from
deivid-rodriguez:full_fix_for_personal_configuration
Jul 13, 2020
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1aab1a6
Fix `traverse_files_upwards` to make searching up to the root possible
deivid-rodriguez f0adb9f
Only look up to the project's root for exclusions
deivid-rodriguez 12d80e5
Ignore configuration files outside of the project
deivid-rodriguez 469ca61
Add a changelog entry
deivid-rodriguez File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ class << self | |
|
||
attr_accessor :debug, :ignore_parent_exclusion, | ||
:disable_pending_cops, :enable_pending_cops | ||
attr_writer :default_configuration | ||
attr_writer :default_configuration, :project_root | ||
|
||
alias debug? debug | ||
alias ignore_parent_exclusion? ignore_parent_exclusion | ||
|
@@ -118,7 +118,7 @@ def possible_new_cops?(config) | |
end | ||
|
||
def add_excludes_from_files(config, config_file) | ||
exclusion_file = find_last_file_upwards(DOTFILE, config_file) | ||
exclusion_file = find_last_file_upwards(DOTFILE, config_file, project_root) | ||
|
||
return unless exclusion_file | ||
return if PathUtil.relative_path(exclusion_file) == PathUtil.relative_path(config_file) | ||
|
@@ -134,6 +134,12 @@ def default_configuration | |
end | ||
end | ||
|
||
# Returns the path rubocop inferred as the root of the project. No file | ||
# searches will go past this directory. | ||
def project_root | ||
@project_root ||= find_project_root | ||
end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I intentionally left this method above in the public section and documented it since I believe it could be useful for extensions. At least it's useful for a cop I'm helping with in the |
||
def warn_on_pending_cops(pending_cops) | ||
return if pending_cops.empty? | ||
|
||
|
@@ -158,7 +164,15 @@ def merge_with_default(config, config_file, unset_nil: true) | |
private | ||
|
||
def find_project_dotfile(target_dir) | ||
find_file_upwards(DOTFILE, target_dir) | ||
find_file_upwards(DOTFILE, target_dir, project_root) | ||
end | ||
|
||
def find_project_root | ||
pwd = Dir.pwd | ||
gems_file = find_last_file_upwards('Gemfile', pwd) || find_last_file_upwards('gems.rb', pwd) | ||
return unless gems_file | ||
|
||
File.dirname(gems_file) | ||
end | ||
|
||
def find_user_dotfile | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only for test code to be able to reset state, the project_root doesn't really change at runtime. I can alternatively revert this change and use
instance_variable_set
inside the test code to reset it.