Class: QueryPackwerk::RuleRewriter::AnonymizeArgumentsRule

Inherits:
BaseRule
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/query_packwerk/rule_rewriter/anonymize_arguments_rule.rb

Constant Summary collapse

SIGIL_ARGS =

Arguments prefixed with a sigil like ‘*arg` and `&fn`

T.let(i[splat block_pass].freeze, T::Array[Symbol])

Constants inherited from BaseRule

BaseRule::ANONYMIZED

Instance Method Summary collapse

Methods inherited from BaseRule

#create_range, #initialize

Constructor Details

This class inherits a constructor from QueryPackwerk::RuleRewriter::BaseRule

Instance Method Details

#on_send(node) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/query_packwerk/rule_rewriter/anonymize_arguments_rule.rb', line 13

def on_send(node)
  return unless node.arguments?

  node.arguments.reject(&:hash_type?).each do |arg|
    arg_node = if SIGIL_ARGS.include?(arg.type)
                 arg.children.first
               else
                 arg
               end

    # Just in case we get strangely shaped nodes
    next unless arg_node.respond_to?(:loc)

    @rewriter.replace(arg_node.loc.expression, ANONYMIZED)
  end
end