Skip to content

Commit

Permalink
Change ConfigLoader#added_features to be a Set.
Browse files Browse the repository at this point in the history
  • Loading branch information
dvandersluis authored and bbatsov committed Jan 12, 2021
1 parent 3e97bcd commit d4d1b3a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
13 changes: 3 additions & 10 deletions lib/rubocop/config_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ class << self
attr_accessor :debug, :ignore_parent_exclusion,
:disable_pending_cops, :enable_pending_cops
attr_writer :default_configuration, :project_root
attr_reader :loaded_features

alias debug? debug
alias ignore_parent_exclusion? ignore_parent_exclusion

def clear_options
@debug = nil
@loaded_features = []
@loaded_features = Set.new
FileFinder.root_level = nil
end

Expand Down Expand Up @@ -174,19 +175,11 @@ def merge_with_default(config, config_file, unset_nil: true)
resolver.merge_with_default(config, config_file, unset_nil: unset_nil)
end

def loaded_features
@loaded_features.flatten.compact.uniq
end

# @api private
# Used to add features that were required inside a config or from
# the CLI using `--require`.
def add_loaded_features(loaded_features)
if instance_variable_defined?(:@loaded_features)
instance_variable_get(:@loaded_features) << loaded_features
else
instance_variable_set(:@loaded_features, [loaded_features])
end
@loaded_features.merge(Array(loaded_features))
end

private
Expand Down
26 changes: 26 additions & 0 deletions spec/rubocop/cli/cli_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,32 @@
end
end

context 'when requiring extension cops in multiple layers' do
before do
create_file('.rubocop-parent.yml', <<~YAML)
require:
- rubocop-performance
YAML

create_file('.rubocop.yml', <<~YAML)
inherit_from: ./.rubocop-parent.yml
require:
- rubocop-rspec
YAML
end

it 'shows with version of extension cops' do
# Run in different process that requiring rubocop-performance and rubocop-rspec
# does not affect other testing processes.
output = `ruby -I . "#{rubocop}" -V --disable-pending-cops`
expect(output).to include(RuboCop::Version::STRING)
expect(output).to match(/Parser \d+\.\d+\.\d+/)
expect(output).to match(/rubocop-ast \d+\.\d+\.\d+/)
expect(output).to match(/rubocop-performance \d+\.\d+\.\d+/)
expect(output).to match(/rubocop-rspec \d+\.\d+\.\d+/)
end
end

context 'when requiring redundant extension cop' do
before do
create_file('ext.yml', <<~YAML)
Expand Down

0 comments on commit d4d1b3a

Please sign in to comment.