Sha256: be18e463a8b715a6060384e75a55ef1b548f4641e7454ada7ada2640301786b6

Contents?: true

Size: 959 Bytes

Versions: 14

Compression:

Stored size: 959 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 = '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(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

14 entries across 14 versions & 1 rubygems

Version Path
rubocop-rspec-2.0.0.pre lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.44.1 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.44.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.43.2 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.43.1 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.43.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.42.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.41.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.40.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.39.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.38.1 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.38.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.37.1 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.37.0 lib/rubocop/rspec/config_formatter.rb