Sha256: 28db59afb5e508c634d615ed4ad379adf9d59736a47485ad91060791042852f3

Contents?: true

Size: 927 Bytes

Versions: 10

Compression:

Stored size: 927 Bytes

Contents

require 'yaml'

module RuboCop
  module RSpec
    # Builds a YAML config file from two config hashes
    class ConfigFormatter
      NAMESPACES = /^(RSpec|Capybara|FactoryBot|Rails)/
      STYLE_GUIDE_BASE_URL = 'http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/'.freeze

      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

10 entries across 10 versions & 1 rubygems

Version Path
rubocop-rspec-1.30.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.29.1 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.29.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.28.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.27.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.26.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.25.1 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.25.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.24.0 lib/rubocop/rspec/config_formatter.rb
rubocop-rspec-1.23.0 lib/rubocop/rspec/config_formatter.rb