Skip to content

v0.4.1 — gox explain

Choose a tag to compare

@kidandcat kidandcat released this 25 May 08:46
· 25 commits to master since this release

What's new

New subcommand: `gox explain ` — prints each rule's reference page from inside the binary.

Each analyzer now ships its reference as a co-located `.md` file, embedded via `//go:embed`. The CLI exposes it two ways:

```sh
gox explain bodyclose # markdown to stdout
gox explain bodyclose --json # { "rule": "...", "doc": "...", "explanation": "..." }
gox explain --json bodyclose # flag position is free, important for agent invocations
```

Every reference page covers:

  • one-line summary
  • what the rule catches (concrete LLM-bug class)
  • bad / good example pair
  • opt-out annotation syntax
  • known limitations

Why embedded. Docs are version-pinned to the binary you have installed. An agent that runs `gox explain ` gets the contract for the exact version, not whatever a docs site happens to show today. The `--json` envelope makes it cheap for agent loops to consume.

Internals. New `Analyzer.Explanation string` field on `pkg/analyzer.Analyzer`. Each analyzer's `init()` does:

```go
//go:embed bodyclose.md
var explanation string

func init() {
analyzer.Register(&analyzer.Analyzer{
Name: "bodyclose",
Doc: "...",
Explanation: explanation,
Run: run,
})
}
```

12 `var explanation string` package-level vars annotated `// global-ok: populated at compile time by //go:embed, never mutated` — dogfooded against `noglobals`.

Coverage

All 12 rules now ship a reference page: banany, bodyclose, contextcheck, errcheck, errorlint, exhaustive, forcetypeassert, goroutine, httptimeout, namedargs, noglobals, shadow.