globalvar

package module
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 7 Imported by: 0

README

Documentation

Overview

Package globalvar provides a go/analysis analyzer enforcing the gomatic immutability/DI standard: package-level state is immutable outside tests. An exported package-level var — a binding any importer can rebind — is reported at its declaration unless allow-listed; an unexported var is reported at each reassignment in non-test code. An unexported var never reassigned outside tests is either an immutable binding (a value Go cannot express as a const — a lookup table, a func value, a //go:embed FS) or a dependency-injection seam reassigned only by the package's tests; both are sanctioned gomatic patterns.

Test files (_test.go) are exempt from both checks: reassignment there is the sanctioned dependency-injection seam, and an exported var declared in a test file (the export_test.go seam) is not importable, so the export rationale does not apply. An allow-listed name (version, Analyzer, Registration, or a -allow extra) is exempt from both the export check and the reassignment watch. Mutation through a pointer alias (p := &v; *p = x) is deliberately out of scope: the analyzer tracks assignment targets, not escape analysis.

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = newAnalyzer()

Analyzer reports package-level vars that are exported or reassigned outside tests.

View Source
var Registration = goyze.Registration{
	Name:       "globalvar",
	Categories: []goyze.Category{"immutability"},
	URL:        "https://docs.gomatic.dev/yze/globalvar",
	Analyzer:   Analyzer,
}

Registration declares this analyzer to the yze framework.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
cmd
yze-go-globalvar command
Command yze-go-globalvar runs the globalvar analyzer as a standalone go/analysis checker (text and -json output, and usable as a `go vet -vettool`).
Command yze-go-globalvar runs the globalvar analyzer as a standalone go/analysis checker (text and -json output, and usable as a `go vet -vettool`).

Jump to

Keyboard shortcuts

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