class RuboCop::Cop::Primer::DeprecatedArguments

This cop ensures that components don't use deprecated arguments

bad Component.new(foo: :deprecated)

good Component.new(foo: :bar)

Constants

DEPRECATED

This is a hash of deprecated arguments and their replacements.

* The top level key is the argument.
* The second level key is the value.
* The seceond level value is a string of the full replacement. e.g. "new_argument: :new_value"
  If the value is nil, then there is no replacement.

e.g. DEPRECATED = {

argument: {
  value: "new_argument: :new_value"
}

}

INVALID_MESSAGE

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubocop/cop/primer/deprecated_arguments.rb, line 254
def autocorrect(node)
  lambda do |corrector|
    replacement = DEPRECATED[node.key.value][node.value.value.to_sym]
    corrector.replace(node, replacement) if replacement.present?
  end
end
on_send(node) click to toggle source
# File lib/rubocop/cop/primer/deprecated_arguments.rb, line 231
def on_send(node)
  return unless valid_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

    key = pair.key.value
    value = pair.value.value.to_sym

    next unless DEPRECATED.key?(key) && DEPRECATED[key].key?(value)

    add_offense(pair, message: INVALID_MESSAGE)
  end
end