Class: Mutineer::Mutators::StatementRemoval

Inherits:
Base
  • Object
show all
Defined in:
lib/mutineer/mutators/statement_removal.rb

Overview

Statement-removal mutator.

Replaces each non-final method statement with nil.

Instance Method Summary collapse

Methods inherited from Base

#mutations_for

Instance Method Details

#visit_statements_node(node) ⇒ void

This method returns an undefined value.

Visits statement nodes and emits removals.

Parameters:

  • node (Prism::StatementsNode)

    statement list to inspect.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mutineer/mutators/statement_removal.rb', line 15

def visit_statements_node(node)
  stmts = node.body
  if stmts.length >= 2
    stmts[0...-1].each do |stmt|
      loc = stmt.location
      @mutations << Mutation.new(
        start_offset: loc.start_offset,
        end_offset: loc.end_offset,
        replacement: "nil",
        operator: :statement_removal
      )
    end
  end
  # Nested statement lists (if/begin/while bodies) are separate StatementsNodes.
  super
end