statement

package
v0.0.0-...-3d49dda Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package statement implements mutation operators that delete whole statements from a function body, answering the question "does the test suite notice when this line never runs?".

Why the operator matches blocks, not statements

The natural reading of "delete a statement" is a mutator whose Applies matches *ast.ExprStmt, *ast.IncDecStmt and *ast.AssignStmt directly. That shape cannot be implemented against a generic go/ast.Walk: replacing a statement requires writing to the slot it occupies in its parent's statement list, and a walk hands a visitor the node alone — no parent, no slot. Recovering the parent would mean threading a parent stack through the engine's walk purely for this one operator.

So the operator matches the *container* instead: an go/ast.BlockStmt or an go/ast.CaseClause, both of which own a []ast.Stmt the operator can index into. One call to Mutate on a container yields one independent mutator.Mutation per eligible statement it holds, each closing over the index it replaces, which preserves the engine's one-mutation-at-a-time contract without any extra walk machinery.

Index

Constants

View Source
const RemoverName = "statement/remover"

RemoverName is the registry name of the statement removal operator.

Variables

This section is empty.

Functions

This section is empty.

Types

type Remover

type Remover struct{}

Remover replaces a single statement with an empty statement, simulating the line having been deleted.

It is stateless: every per-node value lives in the closures returned by Remover.Mutate, so one instance may be walked over many files.

func (*Remover) Applies

func (*Remover) Applies(node ast.Node) bool

Applies reports whether node is a statement container holding at least one removable statement.

The scan is O(len(list)), but blocks and case clauses are a small minority of the nodes in a file, and the loop allocates nothing on either path.

func (*Remover) Mutate

func (*Remover) Mutate(node ast.Node) []mutator.Mutation

Mutate returns one mutation per removable statement in node's statement list.

Each mutation swaps its statement for an go/ast.EmptyStmt on Apply and puts the original ast.Stmt value back on Revert. Mutate itself leaves the AST untouched.

func (*Remover) Name

func (*Remover) Name() string

Name reports the operator's registry name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL