globalvar

package module
v0.2.1 Latest Latest
Warning

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

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

README

yze-go-globalvar

A yze analyzer (category immutability) that reports package-level mutable vars, which the gomatic immutability/dependency-injection standard forbids: prefer a constant or dependency injection. A small allow-listed set of sanctioned package vars (version, Analyzer, Registration) — plus any configured via the -allow flag — is permitted.

  • Rule: yze/globalvar
  • Library: exports Analyzer (a standard go/analysis analyzer) and Registration for the yze aggregator and stickler runner.
  • Binary: cmd/yze-go-globalvar runs it standalone (text/-json, and as a go vet -vettool).
  • Config: -allow takes a comma-separated list of additional permitted package-level var names.

Built on the go-yze framework.

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.

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