Skip to content

Commit

Permalink
Use ConfigLoader.default_configuration for default
Browse files Browse the repository at this point in the history
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 rubocop/rubocop-rails#127
  • Loading branch information
hanachin committed Jan 7, 2020
1 parent d5334b9 commit 0533089
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down Expand Up @@ -4320,3 +4324,4 @@
[@mangara]: https://github.com/mangara
[@pirj]: https://github.com/pirj
[@pawptart]: https://github.com/pawptart
[@hanachin]: https://github.com/hanachin
4 changes: 2 additions & 2 deletions lib/rubocop/config_loader.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cli/cli_options_spec.rb
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/support/cli_spec_behavior.rb
Expand Up @@ -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.
Expand Down

0 comments on commit 0533089

Please sign in to comment.