importrefactor

package
v0.28.15 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: Apache-2.0 Imports: 7 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RefactorFile

func RefactorFile(filename string, rules RewriteRules) (bool, error)

RefactorFile applies the rewrite rules to the given Go file. It returns true if the file was modified.

Types

type RewriteRules

type RewriteRules struct {
	// ImportPathMap maps old import paths to new import paths.
	ImportPathMap map[string]string
	// PackageNameMap maps old package names to new package names.
	PackageNameMap map[string]string
	// TypeNameMap maps old type names to new type names (e.g., "model.Context" -> "Scope").
	// The key is the full identifier or just the name if it's in the same package.
	TypeNameMap map[string]string
	// FunctionNameMap maps old function names to new function names.
	// The key is the full identifier or just the name if it's in the same package.
	FunctionNameMap map[string]string
	// VariableNameMap maps old variable names to new variable names,
	// optionally filtered by their type name.
	VariableNameMap map[string]VariableRename
	// MethodNameMap maps old method names to new method names.
	// The key is the type-qualified method name (e.g., "model.Scope.VariableWithValueGraph").
	MethodNameMap map[string]string
}

RewriteRules defines the mappings for import paths, package names, types, and variables.

type VariableRename

type VariableRename struct {
	NewName  string
	TypeName string // Optional: only rename if the type matches.
}

Jump to

Keyboard shortcuts

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