Documentation
¶
Overview ¶
Package codemod rewrites project code when an incompatible change of kit arrives.
A codemod belongs to the platform version that brings the change. apply runs the ones newer than the version the project was last applied with, which platformgo.lock records, so an upgrade over several versions replays every step in order. A codemod must be idempotent: code that has nothing left to rewrite stays as it is.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change struct {
Path string // relative to the project root
Codemods []string // names of the codemods that changed it
Content []byte
}
Change is a file a run rewrote.
type Codemod ¶
type Codemod struct {
Version string // the platform version that brings the change
Name string
Description string
Fix func(f *File) // rewrites one Go file through File.Replace
}
Codemod is one rewrite.
func All ¶
func All() []Codemod
All are the codemods of the platform, oldest first. Add one with the change of kit that needs it, under the version that will be released with it:
RenameSymbol("v0.3.0", "github.com/aidarbn/platform-go/kit/modules/riverx", "NewQueue", "Queue"),
func Pending ¶
Pending returns the codemods newer than the version the project was applied with, in version order. An empty or invalid version means before codemods existed: all of them.
func RenameSymbol ¶
RenameSymbol is the common codemod: an exported name of a kit package changes.
type File ¶
type File struct {
Path string
Fset *token.FileSet
AST *ast.File
// contains filtered or unexported fields
}
File is a Go file a codemod rewrites. Edits replace source ranges, so comments and layout outside them stay as the developer wrote them.
func (*File) ImportName ¶
ImportName returns the name a package is known by in the file, when it is imported.