Method: RuboCop::Cop::HashShorthandSyntax#on_pair

Defined in:
lib/rubocop/cop/mixin/hash_shorthand_syntax.rb

#on_pair(node) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rubocop/cop/mixin/hash_shorthand_syntax.rb', line 44

def on_pair(node)
  return if ignore_hash_shorthand_syntax?(node)

  hash_key_source = node.key.source

  if enforced_shorthand_syntax == 'always'
    return if node.value_omission? || require_hash_value?(hash_key_source, node)

    message = OMIT_HASH_VALUE_MSG
    replacement = "#{hash_key_source}:"
    self.config_to_allow_offenses = { 'Enabled' => false }
  else
    return unless node.value_omission?

    message = EXPLICIT_HASH_VALUE_MSG
    replacement = "#{hash_key_source}: #{hash_key_source}"
  end

  register_offense(node, message, replacement)
end