Class: Evilution::Mutator::Operator::LastExpressionRemoval

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

Overview

Removes a trailing literal expression (true/false/nil/integer/symbol) from a method body. Targets the idiomatic Ruby pattern ‘def foo?; side_effect; true; end` where the explicit literal return value is the high-signal behavior under test — dropping it makes the method return whatever the preceding statement evaluates to. Strong against predicates and command-query split methods.

Constant Summary collapse

LITERAL_NODE_TYPES =
[
  Prism::TrueNode,
  Prism::FalseNode,
  Prism::NilNode,
  Prism::IntegerNode,
  Prism::SymbolNode
].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_def_node(node) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/evilution/mutator/operator/last_expression_removal.rb', line 20

def visit_def_node(node)
  last_literal = trailing_literal(node)
  if last_literal
    add_mutation(
      offset: last_literal.location.start_offset,
      length: last_literal.location.length,
      replacement: "",
      node: last_literal
    )
  end

  super
end