Skip to content

Commit

Permalink
[Fix #11715] Ensure default configuration loads
Browse files Browse the repository at this point in the history
Fixes #11715.

There was an issue where the default configuration was not loaded
when instantiating cop with no arguments. This patch ensures
default configuration by passing `RuboCop::ConfigLoader.default_configuration`
to `RuboCop::Config.new` default argument.
  • Loading branch information
koic authored and bbatsov committed Mar 23, 2023
1 parent 7962934 commit 7e73f51
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/fix_ensure_default_configuration_loads.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#11715](https://github.com/rubocop/rubocop/issues/11715): Ensure default configuration loads. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def self.create(hash, path, check: true)
end

# rubocop:disable Metrics/AbcSize
def initialize(hash = {}, loaded_path = nil)
def initialize(hash = RuboCop::ConfigLoader.default_configuration, loaded_path = nil)
@loaded_path = loaded_path
@for_cop = Hash.new do |h, cop|
cop_name = cop.respond_to?(:cop_name) ? cop.cop_name : cop
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
let(:hash) { {} }
let(:loaded_path) { 'example/.rubocop.yml' }

describe '.new' do
context 'without arguments' do
subject(:configuration) { described_class.new }

it { expect(configuration['Lint/BooleanSymbol']['SafeAutoCorrect']).to be(false) }
end
end

describe '#validate', :isolated_environment do
subject(:configuration) do
# ConfigLoader.load_file will validate config
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cop/mixin/enforce_superclass_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# rubocop:disable RSpec/FilePath
RSpec.describe RuboCop::Cop::EnforceSuperclass, :restore_registry do
subject(:cop) { cop_class.new }
subject(:cop) { cop_class.new(configuration) }

let(:cop_class) { RuboCop::Cop::RSpec::ApplicationRecord }
let(:msg) { 'Models should subclass `ApplicationRecord`' }
Expand Down

0 comments on commit 7e73f51

Please sign in to comment.