cite-guard

command
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 9 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

Command cite-guard fails the build when a Go comment cites another symbol by file and line where a symbol name would do.

Why this exists

Comments used to reference code as `foo_test.go:315`. Nothing declared that convention; it propagated by each author copying its neighbours. It is expensive, because any insertion displaces an unknown subset of the citations and nothing maintains them. Measured over 25 commits touching internal/e2e/realclaude before the 2026-08-10 cleanup: 419 of 5509 added lines were pure renumbering, the small commits in one ticket family ran 35-49% renumbering, and one commit existed for nothing else. Two 25-minute developer timeouts (#1417, #1452) burned their budgets on it. 22 citations were already dead, pointing at lines that no longer existed.

codegraph indexes this repo, including files behind the e2e_realclaude build tag, so a symbol name resolves on demand and never rots.

The rule: name the symbol, at any depth, single line or range

If a citation resolves to a declaration -- because the line IS one, or is a doc comment on one, or sits anywhere inside one -- name that declaration. A RANGE is a citation too, and rots the same way. Both its ends are resolved: when they agree it reads exactly like a single-line citation, and when they disagree the range spans declarations and the message names both ends, because there is no single symbol to offer.

An earlier version exempted citations more than 20 lines deep, reasoning that there a line number pointed somewhere a name could not reach. The operator overturned it on 2026-08-13, and the argument is better: if a symbol name is not precise enough to locate something, the problem is the size of the declaration, not the citation. A line number used that way is accommodating a defect rather than describing one.

The measurement agrees. All 67 citations the exemption used to permit sit in the biggest declarations in the repo -- trailClassifyRun at 454 lines takes 10 of them, trailRunCases 381, trailGate 343, runProbeRep 170. So a deep citation is a reliable pointer at an oversized function, and the imprecision of naming it is a finding rather than a cost.

Deliberately NOT flagged:

  • Bare `:NNN` citations. They inherit the LAST-NAMED FILE in the comment, not the current one, so resolving them needs comment-context parsing that this guard does not do. A cleanup script that assumed self-file produced confidently wrong symbols; trail_run_outcome_test.go documents the same hazard on #1434's evidence.
  • A range whose ends do not both resolve. Same posture as an ambiguous basename below: a wrong answer is worse than no answer.
  • Anything outside a `//` comment. String literals and code are not this guard's business.

Ranges were exempt until 2026-08-14, on the reasoning that a span carries information a symbol name does not. The 2026-08-13 sweep had already converted 151 of them on the opposite argument and left the exemption standing, so the written rule spent a day recruiting exactly the citations the sweep removed. The operator closed it by keeping ranges out.

Why a guard and not just a style rule

This is the second, different-fabric check for a rule the style guide cannot hold on its own. A written convention is a soft instruction that gets skipped under budget pressure, which is exactly when the agents writing these comments are running, and mimicking the surrounding code is the default behaviour. A rule in CODING-STYLE.md protecting a rule in CODING-STYLE.md shares the same blind spot. Same reasoning as cmd/substrate-guard, which this is modelled on.

Run via `make cite-guard`, wired into `make check` and the check.yml PR gate. Exits non-zero and prints file:line plus the symbol to use instead.

Jump to

Keyboard shortcuts

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