Class: Evilution::Mutator::Operator::ArgumentNilSubstitution

Inherits:
Base
  • Object
show all
Defined in:
lib/evilution/mutator/operator/argument_nil_substitution.rb

Constant Summary collapse

SKIP_TYPES =
[
  Prism::SplatNode,
  Prism::KeywordHashNode,
  Prism::BlockArgumentNode,
  Prism::ForwardingArgumentsNode
].freeze

Instance Attribute Summary

Attributes inherited from Base

#mutations

Instance Method Summary collapse

Methods inherited from Base

#call, clear_parse_cache!, #initialize, operator_name, parsed_tree_for

Constructor Details

This class inherits a constructor from Evilution::Mutator::Base

Instance Method Details

#visit_call_node(node) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/evilution/mutator/operator/argument_nil_substitution.rb', line 13

def visit_call_node(node)
  args = node.arguments&.arguments

  if args && args.length >= 1 && positional_only?(args)
    args.each_index do |i|
      parts = args.each_with_index.map { |a, j| j == i ? "nil" : a.slice }
      replacement = parts.join(", ")

      add_mutation(
        offset: node.arguments.location.start_offset,
        length: node.arguments.location.length,
        replacement: replacement,
        node: node
      )
    end
  end

  super
end