Documentation
¶
Overview ¶
Package resourcetracker provides a shared state machine for linters that track a resource or synchronization primitive acquired in a function body and report when its cleanup call is made manually instead of being deferred.
Linters supply the resource-specific matching rules (how a resource is acquired and how its cleanup call is recognised) while this package owns the common bookkeeping: AST traversal, closure boundaries, reassignment handling, suppression-directive filtering and diagnostic reporting.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAnalyzer ¶
func NewAnalyzer[K comparable](cfg Config[K]) *analysis.Analyzer
NewAnalyzer builds an analysis pass implementing the deferred-cleanup check described by cfg. cfg must not be modified after NewAnalyzer returns.
Types ¶
type Acquisition ¶
type Acquisition[K comparable] struct { Key K Pos token.Pos }
Acquisition describes a resource acquired at Pos and tracked under Key.
type Config ¶
type Config[K comparable] struct { // Name is the analyzer name, also used for nolint directive matching. Name string // Doc is the analyzer documentation string. Doc string // Message is the diagnostic message reported at the acquisition position. Message string // Acquisitions returns the resources acquired by node, if any. Acquisitions func(pass *analysis.Pass, node ast.Node) []Acquisition[K] // CleanupKey returns the tracked resource released by call, if any. CleanupKey func(pass *analysis.Pass, call *ast.CallExpr) (K, bool) }
Config describes a deferred-cleanup linter.
Acquisitions reports the resources acquired by a statement, and CleanupKey reports the tracked resource targeted by a cleanup call. Cleanup calls found inside a defer statement mark the resource as correctly released; cleanup calls found in plain expression or assignment statements mark it as manually released and are reported at the acquisition position.