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