Sha256: 9aad325f83030e4a3447848a566fd2f7f4a13f72e74e1fdf6cb082fc9eecc40b

Contents?: true

Size: 958 Bytes

Versions: 5

Compression:

Stored size: 958 Bytes

Contents

# frozen_string_literal: true

require 'yaml'

module RuboCop
  module RSpec
    # Builds a YAML config file from two config hashes
    class ConfigFormatter
      NAMESPACES = /^(RSpec|Capybara|FactoryBot|Rails)/.freeze
      STYLE_GUIDE_BASE_URL = 'http://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(NAMESPACES, "\n\\1")
      end

      private

      def unified_config
        cops.each_with_object(config.dup) do |cop, unified|
          unified[cop] = config.fetch(cop)
            .merge(descriptions.fetch(cop))
            .merge('StyleGuide' => STYLE_GUIDE_BASE_URL + cop.sub('RSpec/', ''))
        end
      end

      def cops
        (descriptions.keys | config.keys).grep(NAMESPACES)
      end

      attr_reader :config, :descriptions
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-rspec-1.36.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.35.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.34.1 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.34.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.33.0 lib/rubocop/rspec/config_formatter.rb