Method: RuboCop::Cop::Primer::DeprecatedLabelSchemes#on_send

Defined in:
lib/rubocop/cop/primer/deprecated_label_schemes.rb

#on_send(node) ⇒ Object

[View source]

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rubocop/cop/primer/deprecated_label_schemes.rb', line 29

def on_send(node)
  return unless label_node?(node)
  return unless node.arguments?

  # we are looking for hash arguments and they are always last
  kwargs = node.arguments.last

  return unless kwargs.type == :hash

  kwargs.pairs.each do |pair|
    # Skip if we're not dealing with a symbol
    next if pair.key.type != :sym
    next unless pair.value.type == :sym || pair.value.type == :str

    value = pair.value.value.to_sym

    next unless DEPRECATIONS.key?(value)

    add_offense(pair.value, message: INVALID_MESSAGE)
  end
end