Skip to content

Commit

Permalink
Use ConfigLoader.default_configuration for default (#7632)
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

Co-authored-by: Bozhidar Batsov <bozhidar@batsov.com>
  • Loading branch information
hanachin and bbatsov committed Apr 16, 2020
1 parent fc24294 commit 532b681
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -21,6 +21,7 @@
* [#7841](https://github.com/rubocop-hq/rubocop/issues/7841): Fix an error for `Style/TrailingCommaInBlockArgs` when lambda literal (`->`) has multiple arguments. ([@koic][])
* [#7842](https://github.com/rubocop-hq/rubocop/issues/7842): Fix a false positive for `Lint/RaiseException` when Exception without cbase specified under the namespace `Gem` by adding `AllowedImplicitNamespaces` option. ([@koic][])
* `Style/IfUnlessModifier` does not infinite-loop when autocorrecting long lines which use if/unless modifiers and have multiple statements separated by semicolons. ([@alexdowad][])
* [rubocop-hq/rubocop-rails#127](https://github.com/rubocop-hq/rubocop-rails/issues/127): Use `ConfigLoader.default_configuration` for the default config. ([@hanachin][])

### Changes

Expand Down Expand Up @@ -4441,6 +4442,7 @@
[@mangara]: https://github.com/mangara
[@pirj]: https://github.com/pirj
[@pawptart]: https://github.com/pawptart
[@hanachin]: https://github.com/hanachin
[@cetinajero]: https://github.com/cetinajero
[@gfyoung]: https://github.com/gfyoung
[@Tietew]: https://github.com/Tietew
Expand All @@ -4455,4 +4457,4 @@
[@rafaelfranca]: https://github.com/rafaelfranca
[@knu]: https://github.com/knu
[@saurabhmaurya15]: https://github.com/saurabhmaurya15
[@DracoAter]: https://github.com/DracoAter
[@DracoAter]: https://github.com/DracoAter
4 changes: 2 additions & 2 deletions lib/rubocop/config_loader.rb
Expand Up @@ -84,9 +84,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 @@ -671,7 +671,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 532b681

Please sign in to comment.