lib/rubocop/config_loader.rb in rubocop-1.8.1 vs lib/rubocop/config_loader.rb in rubocop-1.9.0
- old
+ new
@@ -23,21 +23,22 @@
include FileFinder
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
- def load_file(file)
+ def load_file(file, check: true)
path = file_path(file)
hash = load_yaml_configuration(path)
# Resolve requires first in case they define additional cops
@@ -50,11 +51,11 @@
resolver.resolve_inheritance_from_gems(hash)
resolver.resolve_inheritance(path, hash, file, debug?)
hash.delete('inherit_from')
- Config.create(hash, path)
+ Config.create(hash, path, check: check)
end
def load_yaml_configuration(absolute_path)
file_contents = read_file(absolute_path)
yaml_code = Dir.chdir(File.dirname(absolute_path)) do
@@ -97,14 +98,14 @@
def configuration_file_for(target_dir)
find_project_dotfile(target_dir) || find_user_dotfile ||
find_user_xdg_config || DEFAULT_FILE
end
- def configuration_from_file(config_file)
+ def configuration_from_file(config_file, check: true)
return default_configuration if config_file == DEFAULT_FILE
- config = load_file(config_file)
+ config = load_file(config_file, check: check)
if ignore_parent_exclusion?
print 'Ignoring AllCops/Exclude from parent folders' if debug?
else
add_excludes_from_files(config, config_file)
end
@@ -172,22 +173,14 @@
# Merges the given configuration with the default one.
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
def file_path(file)