Documentation
¶
Overview ¶
Package runner orchestrates analysis, refactoring, and formatting passes.
Package runner orchestrates analysis, refactoring, and persistence.
Package runner orchestrates analysis, transformation, and code generation.
Index ¶
Constants ¶
const ( // ExitCodeOk indicates successful command execution. ExitCodeOk = 0 // ExitUncheckedError indicates that unhandled errors were found in check mode. ExitUncheckedError = 1 // ExitFatalError indicates a fatal error such as invalid flags, load failures, or IO errors. ExitFatalError = 2 )
Variables ¶
This section is empty.
Functions ¶
func PatchSignature ¶
PatchSignature manually updates the types.Info maps to reflect a change in a function's signature (specifically adding an error return). This allows subsequent analysis passes (like the Injector) to see the correct return types without requiring a generic packages.Load reload (which is slow).
It performs the following: 1. Retrieves the existing function object. 2. Constructs a new types.Signature with the appended 'error' return value. 3. Creates a new types.Func object pointing to this signature. 4. Updates info.Defs to point to the new object. 5. Updates info.Uses to point all existing references to the new object.
info: The package type info. decl: The modified AST declaration (should already have the 'error' field in AST). pkg: The types.Package the function belongs to.
Types ¶
type CheckError ¶
type CheckError struct {
// Count is the number of unhandled error sites detected.
Count int
}
CheckError indicates that unhandled errors were detected during verification mode.
func NewCheckError ¶
func NewCheckError(count int) *CheckError
NewCheckError creates a CheckError representing unhandled errors found in verification.
count: Number of unhandled error sites.
Returns a pointer to CheckError.
func (*CheckError) Error ¶
func (e *CheckError) Error() string
Error returns the human-readable summary of unhandled errors detected.
func (*CheckError) ExitCode ¶
func (e *CheckError) ExitCode() int
ExitCode returns ExitUncheckedError (1).
type FatalError ¶
type FatalError struct {
// Err is the underlying execution failure.
Err error
}
FatalError represents a fatal execution failure (e.g., package loading or IO failure).
func NewFatalError ¶
func NewFatalError(err error) *FatalError
NewFatalError creates a FatalError wrapping an execution error.
err: The underlying cause of the failure.
Returns a pointer to FatalError.
func (*FatalError) Error ¶
func (e *FatalError) Error() string
Error returns the wrapped failure message or a default string if nil.
func (*FatalError) ExitCode ¶
func (e *FatalError) ExitCode() int
ExitCode returns ExitFatalError (2).
func (*FatalError) Unwrap ¶
func (e *FatalError) Unwrap() error
Unwrap returns the underlying error.
type FuncContext ¶
type FuncContext struct {
// Sig is the type signature of the function, resolved from type information.
Sig *types.Signature
// Decl is set if the enclosing function is a named declaration (e.g. func Foo() {}).
Decl *ast.FuncDecl
// Lit is set if the enclosing function is a literal (e.g. func() {}).
Lit *ast.FuncLit
// Node is the AST node corresponding to the function (either Decl or Lit).
Node ast.Node
// TestParam is the name of the *testing.T (or B/F) parameter if this function is a test handler.
// This is populated for top-level Test functions AND subtest closures (t.Run).
TestParam string
}
FuncContext represents the function (Declaration or Literal) enclosing a specific point in code. It provides access to the semantic signature and the syntactic AST node required for refactoring.
func FindEnclosingFunc ¶
FindEnclosingFunc resolves the nearest function wrapping the provided position in the file. It traverses the AST upwards from the position to find either a FuncDecl or a FuncLit. It checks for testing contexts (Test functions or t.Run closures) to ensure correct error handling.
pkg: The package containing the file, populated with syntax and type info. file: The AST file associated with the position. pos: The token position to start the search from.
Returns nil if no function context encloses the position or if type information is missing.
func (*FuncContext) IsLiteral ¶
func (fc *FuncContext) IsLiteral() bool
IsLiteral reports whether the function context is an anonymous function literal.
type Options ¶
type Options struct {
// EnablePreexistingErr enables fixes for functions that already return an error.
EnablePreexistingErr bool
// EnableNonExistingErr enables changing function signatures to add error returns.
EnableNonExistingErr bool
// EnableThirdPartyErr enables checking errors from third-party libraries.
EnableThirdPartyErr bool
// EnableTestRefactor allows modification of test function bodies.
EnableTestRefactor bool
// Check enables CI mode (exit 1 on issues).
Check bool
// ExcludeGlob is a list of file glob patterns to exclude.
ExcludeGlob []string
// ExcludeSymbolGlob is a list of symbol glob patterns to exclude.
ExcludeSymbolGlob []string
// DryRun enables preview mode.
DryRun bool
// UseDefaultExclusions applies the default list of ignored symbols.
UseDefaultExclusions bool
// PanicToReturn enables rewriting of explicit panic() calls.
PanicToReturn bool
// RetainPanics restricts panic replacement to only those wrapping errors.
RetainPanics bool
// Recursive enables recursive directory scanning.
Recursive bool
// Paths to analyze.
Paths []string
// MainHandler strategy for entry points.
MainHandler string
// NonErrorFallback strategy for functions that do not return error.
NonErrorFallback string
// ErrorTemplate template for return statements.
ErrorTemplate string
// Blank enables checking for errors assigned to blank identifier.
Blank bool
// Asserts enables checking for ignored type assertion results.
Asserts bool
// StrictErrcheck enforces strict errcheck parity (exact default exclusions, strict flags).
StrictErrcheck bool
// IgnoreTests disables checking of _test.go files.
IgnoreTests bool
// IgnoreGenerated disables checking of files with generated code headers.
IgnoreGenerated bool
// Exclude specifies path to file containing list of functions to exclude.
Exclude string
// ExcludeOnly specifies that only exclusions from the exclude file should be used.
ExcludeOnly bool
// Tags specifies build tags to include.
Tags []string
// Mod specifies module download mode (readonly or vendor).
Mod string
// AbsPath specifies printing absolute paths to files in reports.
AbsPath bool
// Verbose specifies printing verbose output with selector names.
Verbose bool
// Ignore specifies legacy comma-separated pkg:regex pairs.
Ignore string
// IgnorePkg specifies legacy comma-separated list of package paths to ignore.
IgnorePkg string
// Stdout writer for diagnostic output in check mode.
Stdout io.Writer
// FromErrcheck specifies a file path containing errcheck stdout to auto-fix.
FromErrcheck string
// ErrcheckReader provides an io.Reader containing errcheck stdout to auto-fix.
ErrcheckReader io.Reader
// Reporter collects statistics.
Reporter *report.Reporter
}
Options configuration for the runner.