Documentation
¶
Overview ¶
Package allowedsymbols provides a go/analysis.Analyzer that enforces symbol-level import restrictions on Go source files.
The analyzer checks that every imported symbol is in a given allowlist, that no permanently banned packages are imported, and that every symbol in the allowlist is actually used. It reports violations with file:line:col diagnostics.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAnalyzer ¶
func NewAnalyzer(cfg AnalyzerConfig) *analysis.Analyzer
NewAnalyzer returns a go/analysis.Analyzer that enforces the symbol-level import restrictions described by cfg. Violations are reported via pass.Reportf and appear as diagnostics with proper file:line:col positions.
NewAnalyzer panics if any entry in cfg.Symbols is malformed (no dot separator), matching the behaviour of the test-harness variant.
Types ¶
type AnalyzerConfig ¶
type AnalyzerConfig struct {
// Symbols is the allowlist to enforce (e.g. builtinAllowedSymbols).
// Each entry must be in "importpath.Symbol" form.
Symbols []string
// ExemptImport returns true for import paths that are auto-allowed and
// should not be checked against the allowlist (e.g. same-module imports).
ExemptImport func(importPath string) bool
// ListName is used in diagnostic messages (e.g. "builtinAllowedSymbols").
ListName string
}
AnalyzerConfig configures a single instance of the allowed-symbols analyzer.