Class: Evilution::Mutator::Operator::ArgumentRemoval

Inherits:
Base
  • Object
show all
Defined in:
lib/evilution/mutator/operator/argument_removal.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_removal.rb', line 13

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

  if args && args.length >= 2 && positional_only?(args)
    args.each_index do |i|
      remaining = args.each_with_index.filter_map { |a, j| a.slice if j != i }
      replacement = remaining.join(", ")

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

  super
end