Sha256: a29debbb16119ab291b1b00ab94f211e5d2fcbc2a8d5ba0c77caf9547a0ffed0
Contents?: true
Size: 1.42 KB
Versions: 6869
Compression:
Stored size: 1.42 KB
Contents
# frozen_string_literal: true module RuboCop module Cop # Common functionality for handling percent literal delimiters. class PreferredDelimiters attr_reader :type, :config PERCENT_LITERAL_TYPES = %w[% %i %I %q %Q %r %s %w %W %x].freeze def initialize(type, config, preferred_delimiters) @type = type @config = config @preferred_delimiters = preferred_delimiters end def delimiters preferred_delimiters[type].split(//) end private def ensure_valid_preferred_delimiters invalid = preferred_delimiters_config.keys - (PERCENT_LITERAL_TYPES + %w[default]) return if invalid.empty? raise ArgumentError, "Invalid preferred delimiter config key: #{invalid.join(', ')}" end def preferred_delimiters @preferred_delimiters ||= begin ensure_valid_preferred_delimiters if preferred_delimiters_config.key?('default') Hash[PERCENT_LITERAL_TYPES.map do |type| [type, preferred_delimiters_config[type] || preferred_delimiters_config['default']] end] else preferred_delimiters_config end end end def preferred_delimiters_config config.for_cop('Style/PercentLiteralDelimiters')['PreferredDelimiters'] end end end end
Version data entries
6,869 entries across 6,843 versions & 29 rubygems