codemod

package
v0.4.1-rc5 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: MIT Imports: 0 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package codemod defines the data structures used to represent codification modification scripts for the contextvibes CLI. These structures allow for a standardized way to describe a series of automated changes to files within a codebase.

The core types are:

  • Operation: Defines a single modification to be performed on a file, such as a regular expression replacement or a file deletion. It includes fields like `Type`, `Description`, `FindRegex`, and `ReplaceWith`.
  • FileChangeSet: Groups all `Operation`s intended for a single target file, specified by `FilePath`.
  • ChangeScript: Represents the top-level structure of a codemod script, which is an array of `FileChangeSet`s, allowing modifications across multiple files.

These types are typically unmarshalled from a JSON file (e.g., the default `contextvibes-codemod.json` or a user-specified script) by the `contextvibes codemod` command. The command then interprets these structures to apply the requested changes to the project's files.

This package itself does not contain the execution logic for applying the codemods; that logic resides in the `cmd` package (specifically `cmd/codemod.go`). The primary role of `internal/codemod` is to provide the clear, typed representation of the modification instructions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeScript

type ChangeScript []FileChangeSet

ChangeScript is the top-level structure, representing a list of changes for multiple files.

type FileChangeSet

type FileChangeSet struct {
	//nolint:tagliatelle // JSON keys are fixed by schema.
	FilePath   string      `json:"file_path"`
	Operations []Operation `json:"operations"`
}

FileChangeSet groups all operations for a single file.

type Operation

type Operation struct {
	// Type indicates the kind of operation (e.g., "regex_replace", "add_import").
	Type string `json:"type"`
	// Description provides a human-readable explanation of the operation.
	Description string `json:"description,omitempty"`

	// --- Fields for "regex_replace" type ---
	// FindRegex is the regular expression to find.
	//nolint:tagliatelle // JSON keys are fixed by schema.
	FindRegex string `json:"find_regex,omitempty"`
	// ReplaceWith is the string to replace matches with.
	//nolint:tagliatelle // JSON keys are fixed by schema.
	ReplaceWith string `json:"replace_with,omitempty"`

	// --- Fields for "create_or_overwrite" ---
	Content *string `json:"content,omitempty"` // Pointer to distinguish empty from not-set
	// LineNumber can be used to target a specific line for some operations (not used by basic regex_replace yet).
	//nolint:tagliatelle // JSON keys are fixed by schema.
	LineNumber *int `json:"line_number,omitempty"`
}

Operation defines a single modification to be performed on a file.

Jump to

Keyboard shortcuts

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