usage

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeclarationNode added in v0.0.5

type DeclarationNode struct {
	Decl  astutil.NodeIndex
	Usage Flags
}

DeclarationNode tracks a (re-)declaration node and its usages.

type Diagnostics

type Diagnostics struct {
	Shadows []ShadowUse
	Nested  []NestedAssign
}

Diagnostics contains findings from the usage analysis stage.

type Flags

type Flags uint8

Flags indicate how a variable is used.

const (
	// UsageUsed indicates the variable declaration is used.
	UsageUsed Flags = 1 << iota

	// UsageTypeChange indicates the variable redeclaration implies a type change.
	UsageTypeChange

	// UsageUntypedNil indicates the variable redeclaration is assigned to untyped nil.
	UsageUntypedNil

	// UsageNone indicates the variable redeclaration is unused.
	UsageNone Flags = 0

	// UsageUsedAndTypeChange represents a combination of [UsageUsed] and [UsageTypeChange] flags.
	UsageUsedAndTypeChange = UsageUsed | UsageTypeChange
)

func (Flags) TypeChange

func (f Flags) TypeChange() bool

TypeChange indicates the variable redeclaration implies a type change.

func (Flags) UntypedNil

func (f Flags) UntypedNil() bool

UntypedNil indicates the variable redeclaration is assigned to untyped nil.

func (Flags) Used

func (f Flags) Used() bool

Used indicates the variable declaration is used.

func (Flags) UsedAndTypeChange

func (f Flags) UsedAndTypeChange() bool

UsedAndTypeChange represents a combination of Flags.Used and Flags.TypeChange.

type NestedAssign

type NestedAssign = check.NestedAssign

NestedAssign contains information about a nested variable assign.

type Result

type Result struct {
	// contains filtered or unexported fields
}

Result contains the scope analysis for all variable declarations from stage 1.

func (Result) AllDeclarations added in v0.0.5

func (u Result) AllDeclarations() iter.Seq2[*types.Var, []DeclarationNode]

AllDeclarations returns an iterator over all variables and their corresponding usage lists.

func (Result) AllScopeRanges

func (u Result) AllScopeRanges() iter.Seq2[astutil.NodeIndex, ScopeRange]

AllScopeRanges returns all scope ranges in the result.

func (Result) HasScopeRanges

func (u Result) HasScopeRanges() bool

HasScopeRanges checks if any scope ranges are present in the result.

type ScopeRange

type ScopeRange struct {
	// Decl is the scope where the variable was declared
	Decl,

	Usage *types.Scope
}

ScopeRange represents the scope range for a declaration.

type ShadowUse

type ShadowUse = check.ShadowUse

ShadowUse contains information about a variable use after previously shadowed.

type Stage

type Stage struct {
	*analysis.Pass
	scope.UsageScope
	// contains filtered or unexported fields
}

Stage configures and runs the usage analysis stage. It captures the analysis pass context and configuration to instantiate a usageCollector.

func New added in v0.0.5

func New(p *analysis.Pass, scopes scope.Index, analyzers config.Analyzers, behaviors config.Behaviors) Stage

New initializes a usage.Stage.

func (Stage) TrackUsage

func (us Stage) TrackUsage(ctx context.Context, body inspector.Cursor, f *ast.FuncDecl) (Result, Diagnostics)

TrackUsage collects variable declarations and tracks their usages to determine the minimum scope.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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