Documentation
¶
Overview ¶
Package reachaudit is the exported-reach caller audit iss-33 asked for, as one matcher every audit shares. It is test support: only tests import it, and no production code depends on it.
An exported function exists to be reached from outside its package, so one that no production code outside the package names is silent scaffolding — it compiles, it can rot, and nothing would notice (loud-staging.md). The audit finds them by parsing the module, never by matching text: only a selector on an imported package counts as a caller, so a comment or a string literal naming pkg.X does not, and neither does a selector on a local variable that shadows the import's name. Only Go the release build compiles counts: test files, testdata/ trees, nested modules and worktrees, and any file a build constraint excludes from every release target (`//go:build ignore`, an eval-only tag) name no caller.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Targets = []string{"darwin/arm64", "darwin/amd64", "linux/arm64", "linux/amd64"}
Targets is the set of GOOS/GOARCH pairs the release build compiles, the Makefile's TARGETS. A file counts when any target compiles it, so a caller in a linux-only file reaches its callee on a darwin machine too, and the verdict does not depend on the machine the audit runs on. TestTargetsMatchTheMakefile holds the two lists together.
Functions ¶
func Compiled ¶
Compiled reports whether the release build compiles a non-test Go file named name with contents src for at least one of Targets, honouring both its filename suffixes (_linux, _arm64) and its //go:build line. No build tag is set, so a file under `//go:build ignore` or behind an opt-in tag (an eval lane) is not compiled, and cgo is off, as a cross-compiled release has it.
func ParseSource ¶
ParseSource parses one Go file for Selectors, with the object resolution Selectors relies on to tell an import from a local that shadows its name.
func Selectors ¶
Selectors names every function, type, variable or constant f selects from a package of the module modPath, as "<package dir relative to the module root>.<Name>". names maps a package directory to its package name, the name an import binds when it declares none; a directory it lacks binds the last element of its import path. It counts a selector only when its left side is the name the file imports that package under and that name is not a local declaration: f must be parsed with object resolution (ParseSource, or parser flags without SkipObjectResolution), under which an identifier that resolves to a package import has no object, while a variable, parameter or constant shadowing the import's name resolves to its declaration. A blank or dot import yields no selector, so a function reached only through one reads as unreached: the audit fails loud rather than quiet.
Types ¶
type Reach ¶
Reach maps every exported top-level function in scope, keyed "<package dir relative to the module root>.<Name>" (for example "internal/core/launch.Ship"), to whether production code outside its package selects it. Functions named ...ForTest are left out: the suffix declares a cross-package test seam, exempt by its name.
func Scan ¶
Scan audits the module rooted at root (its go.mod names the module path). scope is a package directory relative to root, slash-separated; the exported functions of that package and of every package beneath it are the ones audited, while the callers are read from the whole module. A Go file that does not parse fails the scan, so a file is never silently counted as naming nothing.