Juggernaut.Operator behaviour (Juggernaut v0.4.0)

Copy Markdown View Source

The behaviour of an operator family (design notes §8.1).

A family is offered every site the walk reaches in one of its positions/0 and returns the replacements it makes there, each with its variant label (or nil for a family without labels). Replacements are Sourceror AST; they reuse the original operands so that the rendered mutant stays small.

use Juggernaut.Operator, name: :relational, positions: [:runtime, :guard], variants: [...] defines name/0, category/0 (from Juggernaut.Operators.Catalog), positions/0 and variants/0; the module implements mutate/2.

Summary

Callbacks

The family's category.

The replacements this family makes at node, or [].

The family name, as Juggernaut.Operators.Catalog lists it.

The positions this family mutates.

The variant labels an ignore filter may name (family:label).

Types

position()

@type position() :: :runtime | :pattern | :guard

replacement()

@type replacement() :: {String.t() | nil, Macro.t()}

Callbacks

category()

@callback category() :: atom()

The family's category.

mutate(node, ctx)

@callback mutate(node :: Macro.t(), ctx :: Juggernaut.Mutator.Context.t()) :: [
  replacement()
]

The replacements this family makes at node, or [].

name()

@callback name() :: atom()

The family name, as Juggernaut.Operators.Catalog lists it.

positions()

@callback positions() :: [position()]

The positions this family mutates.

variants()

@callback variants() :: [String.t()]

The variant labels an ignore filter may name (family:label).