reachaudit

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func Compiled(name string, src []byte) (bool, error)

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

func ParseSource(src []byte) (*ast.File, error)

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

func Selectors(f *ast.File, modPath string, names map[string]string) []string

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

type Reach map[string]bool

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

func Scan(root, scope string) (Reach, error)

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.

func (Reach) Unreached

func (r Reach) Unreached() []string

Unreached lists, sorted, the functions in r that nothing reaches.

Jump to

Keyboard shortcuts

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