codeint ships a built-in go Language plugin that measures every .go file with no configuration required.
Every built-in Metric measures Go: Erosion, Cognitive complexity, Duplication, Verbosity, Import cycles, Import boundaries, Orphan files, and Dependency hygiene.
The go plugin defines no Hazard line rules.
Go and codeint reuse some of the same words with different meanings:
| Go term | codeint term | Meaning |
|---|---|---|
Go module (folder with go.mod) |
Workspace package | Each folder with a go.mod file below the repository root is one Workspace package, measured on its own and selectable with --package <path> |
Go package (folder of .go files) |
Go package | codeint always writes "Go package" for a folder of .go files; an import of a Go package leads to every non-test .go file in that folder |
One .go source file |
module | In codeint reports and GLOSSARY.md, a module is one measured source file |
codeint parses Go through language version 1.27, including type parameters on functions, types, and methods, without adding external parser dependencies.
Files that call C via import "C" (cgo) are measured as Go.
Files that cannot be scanned, such as a file with an unclosed string literal, are listed under skipped and do not stop the run.
- Functions and methods: every function declaration and method declaration with a body counts as one function.
Declarations without bodies are ignored.
A method is named
ReceiverType.MethodName, so methods with the same name on different types stay distinct. Pointer and value receivers produce the same name, and generic receivers use the base type name without type arguments. - Function literals: a function literal is not a separate function. Its source lines and decision points count toward the enclosing function, and its body adds one nesting level for Cognitive complexity.
- Decision points: each
if,for,case(exceptdefault) in aswitchorselect,&&, and||adds one decision point. Acasewith multiple comma-separated expressions counts as 1.elseanddefaultadd 0. - Cognitive complexity: follows codeint's standard nesting rules across
if,for,switch,select,else, function literals, logical operator runs, labelledbreakandcontinue,goto, and direct recursion. Anelse ifchain adds no extra nesting. - Duplication: exact and near-clone detection uses Go tokens without comments and excludes
importdeclarations from clone matching.
After checking any source_sets globs in codeint.jsonc or codeint.json (which always override built-in rules), the go plugin classifies each .go file as follows:
- Vendored: any file under a
vendor/folder. - Generated: any file with a line comment before the first non-comment code matching Go's documented header
// Code generated ... DO NOT EDIT.. Block comments and comments after code do not match. - Test: any file whose name ends in
_test.go, or any file under atestdata/folder at any depth. - Production: every other
.gofile, including platform-specific files such as*_linux.go,*_darwin.go, or files with//go:buildconstraints.
The go plugin ships five zero-false-positive Flagged line rules that feed Verbosity:
else-after-return: anelseblock after anifbranch that always returns. Stays silent when theifheader declares a variable (:=) that theelsebranch uses.if-else-returns-boolean: anif/else, or aniffollowed by areturn, where one branch returnstrueand the other returnsfalse. Stays silent in functions with named results and when either branch does more than return.conditional-yields-boolean: anif/elsewhose only statements assigntrueandfalseto the same variable.trailing-bare-return: a barereturnas the last statement of a function with no return values. Stays silent in functions with named results.redundant-break: an unlabelledbreakas the last statement of acasein aswitchorselect. Stays silent for labelledbreakstatements and forbreakinside a loop.
codeint never flags the idiomatic Go error check (if err != nil { return ..., err }).
codeint reads single and grouped import declarations, with or without package aliases, ., or _, and resolves them from repository paths and go.mod files alone:
- Built-in: any import path whose first segment contains no dot (standard library) and cgo's
"C". - Repository Go packages: any import path under the module path of a repository
go.modfile (longest matching module path wins, including cross-module imports) leads to every.gofile in that folder except*_test.gofiles (ADR 0019). A repository module path that matches no folder, or a folder with no non-test.gofiles, is reported as an Unresolved import. - External: every other import with a dot in its first segment is classified as external under its Go module path.
Because one Go import leads to every non-test file of the imported Go package:
- Import cycles reports its measured value for Go (usually
0, since the Go compiler rejects package cycles). Because codeint evaluates no build conditions, a cycle through platform-specific files such asa_linux.goandb_darwin.gois reported with the real source files involved. - Import boundaries reports every target file in a forbidden Go package along with the importing file. Standard library and external imports never trigger boundary Findings.
Orphan files works on Go repositories with no configuration:
- Programs (
package main): every Production.gofile declaringpackage mainreceives theprogram-startmark, including programs underinternal/such as code generators._test.gofiles never become entry points. - Public Go packages: every non-test Production
.gofile in a folder with nointernalsegment in its path (counted from its module root) is an entry point, so public library packages are not reported as Orphan files. - Unused internal packages: Go packages under
internal/that nothing reaches from an entry point are reported asunreferenced, or astest-onlywhen only_test.gofiles import them. - Multi-file reachability: importing a Go package makes every non-test
.gofile in that folder reachable, even when no file mentions a sibling filename directly. - Custom entry points:
entry_pointsglobs incodeint.jsoncorcodeint.jsonadd entry points alongsidepackage mainand public packages.
Run codeint trace <from> <to> to inspect why a Go file is reachable.
codeint trace reports program-start mark for package main files and lists every file reached by each multi-file Go package import.
codeint reads module, require, replace, and tool directives from each go.mod file in single and grouped forms, and ignores other directives.
A malformed go.mod stops the run with exit code 2 and names the file.
In a multi-module repository, each Go module is checked independently against its own go.mod.
requirewithout// indirect: runtime dependency. Reported underunused_dependencieswhen no file in the module imports it. A module imported only by_test.gofiles stays a runtime dependency with no Finding, matchinggo mod tidy.requirewith// indirect: optional dependency. Satisfies imports (neverunlisted_dependencies) and is never reported asunused_dependencies.tool: a module that provides a package named by atoolline, and that no plainrequireline in the samego.modnames, is a development dependency. Importing it from Production code triggersdev_in_production_dependencies.replace: areplaceline whose target is a folder inside the repository resolves imports of that module to that folder's Go files instead of treating it as external. Areplaceline pointing to another module version or outside the repository changes nothing.- Unlisted imports and ignores: an external import not covered by any
requireortoolentry in the owninggo.modis reported underunlisted_dependencies. List Go module paths independencies.ignoreincodeint.jsoncorcodeint.jsonto silence specific modules.
- Build conditions (
//go:build,// +build, or OS/architecture filename constraints). go.workworkspace files (each folder with ago.modfile is discovered directly).vendor/modules.txt.- C, assembly (
.s), and template files.
Calibrated Go Reference ranges come from a panel of 20 pre-2023 public Go repositories (10th to 90th percentile, ADR 0021, source codeint panel of 20 Go repositories, ADR 0021, codeint 0.6.0):
| Metric | Reference range |
|---|---|
| Erosion | 37.9% to 69.2% |
| Duplication | 4.4% to 18.1% |
| Verbosity | 4.5% to 18.3% |
| Import cycles | 0.0% to 0.0% |
See Built-in Languages and docs/reference.md for all languages, CLI commands, options, and configuration keys.