Muex.Mutator.Builders (Muex v0.8.1)

View Source

Shared construction helpers for mutators.

Mutators describe what they change; these helpers own the common mutation shape and the recurring AST-rewrite patterns so each mutator stays small.

Note: :original_ast is intentionally never set here — Muex.Mutator.walk/3 stamps it onto every mutation from the matched node.

Summary

Functions

Builds a single mutation map. The description is prefixed with the mutator's name/0; the file falls back to "unknown" when the context omits it.

Produces one "delete clause" mutation per index in deletable_positions.

Swaps a module-qualified function call (Mod.fun(...)) for Mod.opposite(...).

Swaps a binary operator for the value mapped to it in swaps.

Functions

build(mutator, mutated_ast, description, context, line)

@spec build(module(), term(), String.t(), map(), non_neg_integer()) :: map()

Builds a single mutation map. The description is prefixed with the mutator's name/0; the file falls back to "unknown" when the context omits it.

clause_deletions(mutator, items, deletable_positions, rebuild, context, line)

@spec clause_deletions(
  module(),
  list(),
  [non_neg_integer()],
  (list() -> Macro.t()),
  map(),
  non_neg_integer()
) :: [map()]

Produces one "delete clause" mutation per index in deletable_positions.

items is the full list a clause is removed from; rebuild turns a reduced list back into the enclosing AST node. Labels are 1-based over the deletable positions (delete clause N of M).

module_fn_swap(arg1, context, mutator, modules, opposites)

@spec module_fn_swap(Macro.t(), map(), module(), [atom()], %{
  required(atom()) => atom()
}) :: [map()]

Swaps a module-qualified function call (Mod.fun(...)) for Mod.opposite(...).

Returns a single mutation when mod is in modules and fun is a key in opposites, otherwise an empty list. The module and arguments are preserved.

operator_swap(arg1, context, mutator, swaps)

@spec operator_swap(Macro.t(), map(), module(), %{required(atom()) => atom()}) :: [
  map()
]

Swaps a binary operator for the value mapped to it in swaps.

Returns a single mutation when the operator is a key in swaps, otherwise an empty list. The two operands are preserved.