Sha256: be6d0dad81ba15f1c792e333ccdc59ec93c2197d2017cdbd42c42adbe6c7a1ce
Contents?: true
Size: 1.34 KB
Versions: 8
Compression:
Stored size: 1.34 KB
Contents
# frozen_string_literal: true require 'yaml' module RuboCop module RSpecRails # Builds a YAML config file from two config hashes class ConfigFormatter EXTENSION_ROOT_DEPARTMENT = %r{^(RSpecRails/)}.freeze SUBDEPARTMENTS = [].freeze AMENDMENTS = [].freeze COP_DOC_BASE_URL = 'https://www.rubydoc.info/gems/rubocop-rspec_rails/RuboCop/Cop/' def initialize(config, descriptions) @config = config @descriptions = descriptions end def dump YAML.dump(unified_config) .gsub(EXTENSION_ROOT_DEPARTMENT, "\n\\1") .gsub(/^(\s+)- /, '\1 - ') .gsub('"~"', '~') end private def unified_config cops.each_with_object(config.dup) do |cop, unified| next if SUBDEPARTMENTS.include?(cop) || AMENDMENTS.include?(cop) replace_nil(unified[cop]) unified[cop].merge!(descriptions.fetch(cop)) unified[cop]['Reference'] = reference(cop) end end def cops (descriptions.keys | config.keys).grep(EXTENSION_ROOT_DEPARTMENT) end def replace_nil(config) config.each do |key, value| config[key] = '~' if value.nil? end end def reference(cop) COP_DOC_BASE_URL + cop end attr_reader :config, :descriptions end end end
Version data entries
8 entries across 8 versions & 2 rubygems