analyzers

package
v0.0.0-...-d9a4191 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangesToPlan

func ChangesToPlan(changes []wstypes.Change) *wstypes.RefactoringPlan

ChangesToPlan creates a RefactoringPlan from a set of changes.

func DiagnosticsToChanges

func DiagnosticsToChanges(fset *token.FileSet, diags []analysis.Diagnostic) []wstypes.Change

DiagnosticsToChanges converts diagnostics with SuggestedFixes into types.Change slices. It picks the first SuggestedFix from each diagnostic (if any).

func FillOldText

func FillOldText(ws *wstypes.Workspace, changes []wstypes.Change) []wstypes.Change

FillOldText populates each change's OldText from the workspace's copy of the file it applies to.

This serves two purposes. A dry run renders OldText as the "before" side of its diff, so without it the caller reviews a preview that only shows what the code would become. And on apply, Serializer.applyChange verifies OldText against the bytes actually at those offsets, turning a stale-offset bug into a clean error instead of a corrupted file.

Changes whose file or offsets are not found in the workspace are left as-is.

Types

type RunResult

type RunResult struct {
	Result      any
	Diagnostics []analysis.Diagnostic
}

RunResult holds the output of running an analyzer across one or more packages.

func Run

func Run(ws *wstypes.Workspace, a *analysis.Analyzer, pkgFilter string) (*RunResult, error)

Run executes an analyzer against workspace packages and returns its typed result plus any diagnostics reported. If pkgFilter is non-empty, only the matching package is analysed; otherwise all packages are analysed.

func RunPackage

func RunPackage(ws *wstypes.Workspace, a *analysis.Analyzer, pkg *wstypes.Package) (*RunResult, error)

RunPackage executes an analyzer against a single workspace package.

Directories

Path Synopsis
Package boolsimplify walks the `!` operators already written in source and removes the ones srctext.PushNeg can push inward with De Morgan's laws, where doing so strictly reduces the number of `!` operators.
Package boolsimplify walks the `!` operators already written in source and removes the ones srctext.PushNeg can push inward with De Morgan's laws, where doing so strictly reduces the number of `!` operators.
Package deepifelse detects nested if-else chains that should be flattened into guard clauses, and rewrites the ones it can.
Package deepifelse detects nested if-else chains that should be flattened into guard clauses, and rewrites the ones it can.
Package earlyreturn detects conditionals that keep the happy path indented and rewrites them as guard clauses, so the main flow sits at the left margin.
Package earlyreturn detects conditionals that keep the happy path indented and rewrites them as guard clauses, so the main flow sits at the left margin.
Package errorwrap provides a go/analysis analyzer that detects improper error wrapping patterns: bare error returns, fmt.Errorf with %v instead of %w, and fmt.Errorf calls with no descriptive context message.
Package errorwrap provides a go/analysis analyzer that detects improper error wrapping patterns: bare error returns, fmt.Errorf with %v instead of %w, and fmt.Errorf calls with no descriptive context message.
Package filedata provides a pass-through analyzer that makes raw file content available to downstream analyzers via pass.ResultOf.
Package filedata provides a pass-through analyzer that makes raw file content available to downstream analyzers via pass.ResultOf.
Package srctext provides helpers for lifting verbatim source text out of an AST node, and for the small syntactic rewrites (condition inversion) that the flattening analyzers share.
Package srctext provides helpers for lifting verbatim source text out of an AST node, and for the small syntactic rewrites (condition inversion) that the flattening analyzers share.
Package stmtfacts answers the two questions every flattening analyzer has to ask before it may drop an `else`: does this branch hand control away for good, and would dedenting that block redeclare a name the enclosing scope already uses.
Package stmtfacts answers the two questions every flattening analyzer has to ask before it may drop an `else`: does this branch hand control away for good, and would dedenting that block redeclare a name the enclosing scope already uses.
Package switchchain detects if/else-if/else chains that should be switch statements, and rewrites the ones it can.
Package switchchain detects if/else-if/else chains that should be switch statements, and rewrites the ones it can.

Jump to

Keyboard shortcuts

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