Help us shape the future of Go! Take the 2026 Go Developer Survey

codemod

package
v0.92.8 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package codemod provides source-preserving edits to the authored AW AST used by workflow linters. Transformations never operate on compiled defaults.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(content string, transform func(*Frontmatter) error) (string, bool, error)

Apply runs an atomic transformation. Errors return the original content, even if earlier operations in the callback succeeded. No-op input is byte-identical.

Types

type Frontmatter

type Frontmatter struct {
	Document *aw.Document
	// contains filtered or unexported fields
}

Frontmatter keeps the authored document and its source in sync after each edit. Read configuration through Document; mutate it through Edit or the path helpers.

func (*Frontmatter) Comment

func (f *Frontmatter) Comment(path []string, text string) error

Comment appends a single-line annotation to a mapping field without replacing existing comments or changing the document's configuration.

func (*Frontmatter) Edit

func (f *Frontmatter) Edit(transform func(*aw.Document) error) error

Edit applies arbitrary semantic edits to an independent AW document, retaining unchanged YAML nodes through the Actions source merger and preserving the body.

func (*Frontmatter) Lookup

func (f *Frontmatter) Lookup(path ...string) (any, bool)

Lookup resolves an exact mapping path, distinguishing absent fields from null.

func (*Frontmatter) MergeSequence

func (f *Frontmatter) MergeSequence(path, destination []string) error

MergeSequence appends unique source entries to a destination sequence, retaining authored entry comments when both sequences use block syntax.

func (*Frontmatter) Move

func (f *Frontmatter) Move(path, destination []string) error

Move relocates a field without flattening nested values or losing its source spelling. Existing destinations are never overwritten.

func (*Frontmatter) PruneEmpty

func (f *Frontmatter) PruneEmpty(path ...string) error

PruneEmpty removes an empty mapping only when it has no authored comments.

func (*Frontmatter) Remove

func (f *Frontmatter) Remove(path ...string) error

Remove deletes exactly one field. Empty parents are retained by default.

func (*Frontmatter) Rename

func (f *Frontmatter) Rename(path []string, newKey string) error

Rename changes only the key token, including in flow mappings and quoted keys. An existing destination is authoritative, including an explicit null value.

func (*Frontmatter) RewriteText

func (f *Frontmatter) RewriteText(transform func(string) string) error

RewriteText supports lexical migrations that intentionally include YAML comments. AW source boundaries keep the Markdown body outside the transform.

func (*Frontmatter) Set

func (f *Frontmatter) Set(path []string, value any) error

Set sets a mapping path without overwriting non-mapping ancestors.

Jump to

Keyboard shortcuts

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