lib/rubocop/config_loader.rb in rubocop-0.50.0 vs lib/rubocop/config_loader.rb in rubocop-0.51.0

- old
+ new

@@ -16,33 +16,38 @@ AUTO_GENERATED_FILE = '.rubocop_todo.yml'.freeze class << self include ConfigLoaderResolver - attr_accessor :debug, :auto_gen_config + attr_accessor :debug, :auto_gen_config, :ignore_parent_exclusion attr_writer :root_level # The upwards search is stopped at this level. attr_writer :default_configuration alias debug? debug alias auto_gen_config? auto_gen_config + alias ignore_parent_exclusion? ignore_parent_exclusion def clear_options @debug = @auto_gen_config = @root_level = nil end - def load_file(path) - path = File.absolute_path(path) + def load_file(file) + return if file.nil? + path = File.absolute_path( + file.is_a?(RemoteConfig) ? file.file : file + ) + hash = load_yaml_configuration(path) # Resolve requires first in case they define additional cops resolve_requires(path, hash) add_missing_namespaces(path, hash) target_ruby_version_to_f!(hash) resolve_inheritance_from_gems(hash, hash.delete('inherit_gem')) - resolve_inheritance(path, hash) + resolve_inheritance(path, hash, file) hash.delete('inherit_from') create_config(hash, path) end @@ -81,29 +86,33 @@ result[key] = merge(base_hash[key], derived_hash[key]) end result end - def base_configs(path, inherit_from) + def base_configs(path, inherit_from, file) configs = Array(inherit_from).compact.map do |f| - if f =~ /\A#{URI::DEFAULT_PARSER.make_regexp(%w[http https])}\z/ - f = RemoteConfig.new(f, File.dirname(path)).file - else - f = File.expand_path(f, File.dirname(path)) - - if auto_gen_config? - next if f.include?(AUTO_GENERATED_FILE) - end - - print 'Inheriting ' if debug? - end - load_file(f) + load_file(inherited_file(path, f, file)) end configs.compact end + def inherited_file(path, inherit_from, file) + regex = URI::DEFAULT_PARSER.make_regexp(%w[http https]) + if inherit_from =~ /\A#{regex}\z/ + f = RemoteConfig.new(inherit_from, File.dirname(path)) + elsif file.is_a?(RemoteConfig) + f = file.inherit_from_remote(inherit_from, path) + else + f = File.expand_path(inherit_from, File.dirname(path)) + + return if auto_gen_config? && f.include?(AUTO_GENERATED_FILE) + print 'Inheriting ' if debug? + end + f + end + # Returns the path of .rubocop.yml searching upwards in the # directory structure starting at the given directory where the # inspected file is. If no .rubocop.yml is found there, the # user's home directory is checked. If there's no .rubocop.yml # there either, the path to the default file is returned. @@ -113,15 +122,22 @@ def configuration_from_file(config_file) config = load_file(config_file) return config if config_file == DEFAULT_FILE - found_files = config_files_in_path(config_file) - if found_files.any? && found_files.last != config_file - print 'AllCops/Exclude ' if debug? - config.add_excludes_from_higher_level(load_file(found_files.last)) + if ignore_parent_exclusion? + print 'Ignoring AllCops/Exclude from parent folders' if debug? + else + add_excludes_from_files(config, config_file) end merge_with_default(config, config_file) + end + + def add_excludes_from_files(config, config_file) + found_files = config_files_in_path(config_file) + return unless found_files.any? && found_files.last != config_file + print 'AllCops/Exclude ' if debug? + config.add_excludes_from_higher_level(load_file(found_files.last)) end def default_configuration @default_configuration ||= begin print 'Default ' if debug?