Documentation
¶
Overview ¶
Package analysis schedules native rules over shared run-owned representations.
Index ¶
- Constants
- func AdaptAnalyzer(analyzer *goanalysis.Analyzer, options AnalyzerAdapterOptions) (rules.Rule, error)
- func AdaptAnalyzerFactory(factory AnalyzerFactory, options AnalyzerAdapterOptions) (rules.Rule, error)
- func OrderDiagnostics(diagnostics []rules.Diagnostic) []rules.Diagnostic
- func RunControlFlow(ctx context.Context, loaded PackageLoadResult, registry *rules.Registry, ...) ([]rules.Diagnostic, error)
- func RunSSA(ctx context.Context, loaded PackageLoadResult, registry *rules.Registry, ...) ([]rules.Diagnostic, error)
- func RunSyntax(ctx context.Context, file *source.File, registry *rules.Registry, ...) ([]rules.Diagnostic, error)
- func RunTypes(ctx context.Context, loaded PackageLoadResult, registry *rules.Registry, ...) ([]rules.Diagnostic, error)
- type AnalyzerAdapterOptions
- type AnalyzerFactory
- type AnalyzerFixMapping
- type AnalyzerFlagBinding
- type ModuleMode
- type PackageCacheOptions
- type PackageDiagnostic
- type PackageLoadOptions
- type PackageLoadResult
- type PackageResult
- type PackageSourceProblem
- type PackageSourceSet
- type Result
- type RunOptions
Constants ¶
const ( // ModuleReadonly refuses go.mod and go.sum updates. ModuleReadonly ModuleMode = "readonly" // ModuleVendor loads dependencies from the selected vendor tree. ModuleVendor ModuleMode = "vendor" // DefaultMaxPackages bounds the complete package graph retained by one // typed analysis load. DefaultMaxPackages = 10_000 // DefaultMaxSourceFiles bounds unique physical Go sources retained by one // typed analysis load. DefaultMaxSourceFiles = 20_000 // DefaultMaxSourceBytes bounds aggregate unique physical Go source bytes // retained by one typed analysis load. DefaultMaxSourceBytes int64 = 256 << 20 )
Variables ¶
This section is empty.
Functions ¶
func AdaptAnalyzer ¶
func AdaptAnalyzer( analyzer *goanalysis.Analyzer, options AnalyzerAdapterOptions, ) (rules.Rule, error)
AdaptAnalyzer wraps one suitable go/analysis analyzer as a native rule.
func AdaptAnalyzerFactory ¶
func AdaptAnalyzerFactory( factory AnalyzerFactory, options AnalyzerAdapterOptions, ) (rules.Rule, error)
AdaptAnalyzerFactory wraps independently constructed analyzer graphs so native options can be bound without mutating shared flag state.
func OrderDiagnostics ¶
func OrderDiagnostics(diagnostics []rules.Diagnostic) []rules.Diagnostic
OrderDiagnostics returns one canonically ordered diagnostic slice.
func RunControlFlow ¶
func RunControlFlow( ctx context.Context, loaded PackageLoadResult, registry *rules.Registry, selection []rules.Selection, ) ([]rules.Diagnostic, error)
RunControlFlow executes selected CFG-tier rules once per function over one graph shared by all eligible rules.
func RunSSA ¶
func RunSSA( ctx context.Context, loaded PackageLoadResult, registry *rules.Registry, selection []rules.Selection, ) ([]rules.Diagnostic, error)
RunSSA executes selected SSA-tier rules once per source function through one program shared by all eligible rules and selected packages.
func RunSyntax ¶
func RunSyntax( ctx context.Context, file *source.File, registry *rules.Registry, selection []rules.Selection, ) ([]rules.Diagnostic, error)
RunSyntax executes selected syntax rules through one shared AST traversal.
func RunTypes ¶
func RunTypes( ctx context.Context, loaded PackageLoadResult, registry *rules.Registry, selection []rules.Selection, ) ([]rules.Diagnostic, error)
RunTypes executes selected types-tier rules through one shared package AST traversal over the exact source versions captured by LoadPackages.
Types ¶
type AnalyzerAdapterOptions ¶
type AnalyzerAdapterOptions struct {
Metadata rules.Metadata
SuggestedFixes []AnalyzerFixMapping
FlagBindings []AnalyzerFlagBinding
ReadOnlyAudited bool
}
AnalyzerAdapterOptions supplies the native product contract for an analyzer.
type AnalyzerFactory ¶
type AnalyzerFactory func() *goanalysis.Analyzer
AnalyzerFactory constructs one independent analyzer graph for a single run.
type AnalyzerFixMapping ¶
type AnalyzerFixMapping struct {
Message string
Name string
Description string
Safety rules.FixSafety
Audited bool
}
AnalyzerFixMapping binds one exact go/analysis suggestion to native metadata.
type AnalyzerFlagBinding ¶
AnalyzerFlagBinding maps one native typed option to one analyzer flag.
type ModuleMode ¶
type ModuleMode string
ModuleMode selects a non-mutating Go module resolution policy.
type PackageCacheOptions ¶
type PackageCacheOptions struct {
Store *cache.Store
ToolVersion string
BuildGoVersion string
SourceGoVersion string
Configuration cache.Digest
CGOEnabled bool
FormatterMode string
}
PackageCacheOptions binds a caller-owned persistent store to the complete non-source identity of one typed analysis run. Source, package, module, workspace, environment, export, overlay, and imported-fact inputs are derived from the exact package load.
type PackageDiagnostic ¶
type PackageDiagnostic struct {
PackageID string
Position string
Message string
Kind packages.ErrorKind
}
PackageDiagnostic is one canonical package-loading or type-checking error.
type PackageLoadOptions ¶
type PackageLoadOptions struct {
Dir string
Patterns []string
Requirement rules.Requirement
Tests bool
LoadDependencySyntax bool
BuildTags []string
ModuleMode ModuleMode
Env []string
Overlay map[string][]byte
AllowNetwork bool
GOOS string
GOARCH string
MaxPackages int
MaxSourceFiles int
MaxSourceBytes int64
}
PackageLoadOptions defines one run-owned Go package loading request.
type PackageLoadResult ¶
type PackageLoadResult struct {
Requirement rules.Requirement
Packages []*packages.Package
Diagnostics []PackageDiagnostic
Sources PackageSourceSet
}
PackageLoadResult owns one compatible typed package graph for a run.
func LoadPackages ¶
func LoadPackages(ctx context.Context, options PackageLoadOptions) (PackageLoadResult, error)
LoadPackages loads the typed prerequisite shared by types, CFG, and SSA tiers. Lexical and syntax-only execution must use the file-owned frontend and never reach this boundary.
type PackageResult ¶
type PackageResult struct {
Requirement rules.Requirement
Selection []rules.Selection
LoadDiagnostics []PackageDiagnostic
SourceProblems []PackageSourceProblem
Sources PackageSourceSet
Files []Result
}
PackageResult is one suppression-aware package analysis run over a shared typed load.
func RunPackages ¶
func RunPackages( ctx context.Context, registry *rules.Registry, options RunOptions, loadOptions PackageLoadOptions, ) (PackageResult, error)
RunPackages resolves a typed rule plan, loads its maximum prerequisite once, and combines syntax, types, CFG, and SSA diagnostics before suppressing.
type PackageSourceProblem ¶
PackageSourceProblem records why one captured source is diagnostic-only.
type PackageSourceSet ¶
type PackageSourceSet struct {
// contains filtered or unexported fields
}
PackageSourceSet is one immutable index of the exact bytes parsed by a package load.
func (PackageSourceSet) Lookup ¶
func (s PackageSourceSet) Lookup(path string) (*source.File, bool)
Lookup returns the immutable source version parsed for path.
func (PackageSourceSet) Paths ¶
func (s PackageSourceSet) Paths() []string
Paths returns normalized physical source identities in canonical order.
func (PackageSourceSet) Problems ¶
func (s PackageSourceSet) Problems() []PackageSourceProblem
Problems returns source-model failures in canonical order.
type Result ¶
type Result struct {
Path string
Digest source.Digest
Requirement rules.Requirement
Selection []rules.Selection
Diagnostics []rules.Diagnostic
Suppressed []suppressions.SuppressedDiagnostic
UnusedSuppressions []suppressions.Directive
SuppressionProblems []suppressions.Problem
}
Result is one reporter-ready syntax analysis result over one source version.
type RunOptions ¶
type RunOptions struct {
SourceGoVersion string
Preset rules.Preset
Overrides map[string]rules.Severity
RuleOptions map[string]rules.OptionSet
RequireSuppressionReason bool
SuppressionExpiryCutoff string
Cache *PackageCacheOptions
}
RunOptions selects native rules and suppression policy for one source file.