From 05330896ab3390b32ad6f7aa1ba4690451c3d66b Mon Sep 17 00:00:00 2001 From: Seiei Miyagi Date: Tue, 7 Jan 2020 02:30:14 +0900 Subject: [PATCH] Use ConfigLoader.default_configuration for default When the config file path is same as the default config file, use `ConfigLoader.default_configuration` instead of create a new config. Because some plugins add their default config values to `ConfigLoader.default_configuration`. So the Cops of the plugins expect that default config values exists. Fix https://github.com/rubocop-hq/rubocop-rails/issues/127 --- CHANGELOG.md | 5 +++++ lib/rubocop/config_loader.rb | 4 ++-- spec/rubocop/cli/cli_options_spec.rb | 2 +- spec/support/cli_spec_behavior.rb | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3dbe877be1..7417378dc31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### Bug fixes + +* [rubocop-hq/rubocop-rails#127](https://github.com/rubocop-hq/rubocop-rails/issues/127): Use `ConfigLoader.default_configuration` for the default config. ([@hanachin][]) + ## 0.79.0 (2020-01-06) ### New features @@ -4320,3 +4324,4 @@ [@mangara]: https://github.com/mangara [@pirj]: https://github.com/pirj [@pawptart]: https://github.com/pawptart +[@hanachin]: https://github.com/hanachin diff --git a/lib/rubocop/config_loader.rb b/lib/rubocop/config_loader.rb index 9f969fdc21b..7683cba25d1 100644 --- a/lib/rubocop/config_loader.rb +++ b/lib/rubocop/config_loader.rb @@ -83,9 +83,9 @@ def configuration_file_for(target_dir) end def configuration_from_file(config_file) - config = load_file(config_file) - return config if config_file == DEFAULT_FILE + return ConfigLoader.default_configuration if config_file == DEFAULT_FILE + config = load_file(config_file) if ignore_parent_exclusion? print 'Ignoring AllCops/Exclude from parent folders' if debug? else diff --git a/spec/rubocop/cli/cli_options_spec.rb b/spec/rubocop/cli/cli_options_spec.rb index ca8ce639b8a..270c77b334d 100644 --- a/spec/rubocop/cli/cli_options_spec.rb +++ b/spec/rubocop/cli/cli_options_spec.rb @@ -508,7 +508,7 @@ class SomeCop < Cop home = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) expect($stdout.string.lines.grep(/configuration/).map(&:chomp)) .to eq(["For #{abs('')}:" \ - " configuration from #{home}/config/default.yml"]) + " Default configuration from #{home}/config/default.yml"]) end it 'shows cop names' do diff --git a/spec/support/cli_spec_behavior.rb b/spec/support/cli_spec_behavior.rb index 59dc649a8f5..7a0f6fbfcae 100644 --- a/spec/support/cli_spec_behavior.rb +++ b/spec/support/cli_spec_behavior.rb @@ -11,6 +11,7 @@ def abs(path) before do RuboCop::ConfigLoader.debug = false + RuboCop::ConfigLoader.default_configuration = nil # OPTIMIZE: Makes these specs faster. Work directory (the parent of # .rubocop_cache) is removed afterwards anyway.