lib/rubocop/config_loader.rb in rubocop-0.15.0 vs lib/rubocop/config_loader.rb in rubocop-0.16.0
- old
+ new
@@ -15,27 +15,20 @@
DEFAULT_FILE = File.join(RUBOCOP_HOME, 'config', 'default.yml')
AUTO_GENERATED_FILE = 'rubocop-todo.yml'
class << self
attr_accessor :debug
+ attr_writer :root_level # The upwards search is stopped at this level.
alias_method :debug?, :debug
def load_file(path)
path = File.absolute_path(path)
- hash = YAML.load_file(path)
+ hash = YAML.load_file(path) || {}
puts "configuration from #{path}" if debug?
contains_auto_generated_config = false
- base_configs(path, hash['inherit_from']).reverse_each do |base_config|
- if File.basename(base_config.loaded_path) == DOTFILE
- make_excludes_absolute(base_config)
- end
- base_config.each do |key, value|
- if value.is_a?(Hash)
- hash[key] = hash.key?(key) ? merge(value, hash[key]) : value
- end
- end
+ resolve_inheritance(path, hash) do |base_config|
if base_config.loaded_path.include?(AUTO_GENERATED_FILE)
contains_auto_generated_config = true
end
end
@@ -133,10 +126,24 @@
result
end
private
+ def resolve_inheritance(path, hash)
+ base_configs(path, hash['inherit_from']).reverse_each do |base_config|
+ if File.basename(base_config.loaded_path) == DOTFILE
+ make_excludes_absolute(base_config)
+ end
+ base_config.each do |key, value|
+ if value.is_a?(Hash)
+ hash[key] = hash.key?(key) ? merge(value, hash[key]) : value
+ end
+ end
+ yield base_config
+ end
+ end
+
def config_files_in_path(target)
possible_config_files = dirs_to_search(target).map do |dir|
File.join(dir, DOTFILE)
end
possible_config_files.select { |config_file| File.exist?(config_file) }
@@ -144,9 +151,10 @@
def dirs_to_search(target_dir)
dirs_to_search = []
target_dir_pathname = Pathname.new(File.expand_path(target_dir))
target_dir_pathname.ascend do |dir_pathname|
+ break if dir_pathname.to_s == @root_level
dirs_to_search << dir_pathname.to_s
end
dirs_to_search << Dir.home
dirs_to_search
end