Skip to content

feat(guard): guard Go - #786

Merged
mick-gsk merged 1 commit into
mainfrom
feat/guard-go
Jul 29, 2026
Merged

mick-gsk merged 1 commit into
mainfrom
feat/guard-go

Conversation

@mick-gsk

Copy link
Copy Markdown
Owner

Closes #779. I opened it as a good-first-issue; a contributor magnet only works once contributors exist, and shipping it widens the audience now.

Measured on real Go repositories

files speaks on
cobra 36 0.0 %
gin 99 2.0 %

gin's two are real — Binding is defined in both binding.go and binding_nomsgpack.go.

Two decisions worth naming

Methods on receivers are not indexed. #779 argued for including them, since func (s *Store) Validate() is package-level API in Go. The noise measurement that came between then and now argued louder: String, Error, Read and Close sit on every type in a package, and methods are excluded in Python and TypeScript for exactly that reason. Evidence beat the plan, and the test says so.

Trailing-segment matching is reserved for Go. Go imports carry the whole module path (github.com/org/repo/internal/db) while the repository knows itself as internal/db, so the resolver drops leading segments until something matches — no go.mod parsing. Applying that rule to TypeScript would resolve lodash/fp onto a directory named fp, and date-fns has one. test_trailing_segment_matching_is_reserved_for_go pins the boundary.

The type (...) block form is deliberately unsupported: matching names at one indent level would also match struct fields, and a struct field read as a type declaration is precisely the invented symbol these patterns exist to prevent.

A bug in the measurement tool

gin reported zero cross-directory imports. That was too clean, and the same instinct has now paid off twice (#783).

measure_boundary_reach called import_to_dir without a suffix, so every Go module path fell through the TypeScript branch and resolved to nothing — a tidy zero for a signal that was working fine. With the suffix passed:

gin  boundary reach: 21 files import across a directory over 14 distinct edges;
     writing 7 of them fresh (7.1%) would announce a first-ever crossing

cobra stays at 0, correctly — it is essentially one package.

Verification

134 guard tests (11 new), all nine gates, both Go repositories within the noise budget, ruff and mypy clean, markdownlint clean.

🤖 Generated with Claude Code

Closes #779

Measured on real Go repositories: cobra speaks on 0 of 36 files, gin on 2 of 99
— and gin's two are real, `Binding` being defined in both `binding.go` and
`binding_nomsgpack.go`.

Two decisions worth naming.

**Methods on receivers are not indexed.** #779 argued for including them, since
`func (s *Store) Validate()` is package-level API in Go. The noise measurement
that came between then and now argued louder: `String`, `Error`, `Read` and
`Close` sit on every type in a package, and methods are excluded in Python and
TypeScript for exactly that reason. Evidence beat the plan.

**Trailing-segment matching is reserved for Go.** Go imports carry the whole
module path (`github.com/org/repo/internal/db`) while the repository knows
itself as `internal/db`, so the resolver drops leading segments until something
matches — no `go.mod` parsing needed. Applying the same rule to TypeScript
would resolve `lodash/fp` onto a directory named `fp`, and date-fns has one; a
test pins that boundary.

The `type (...)` block form is deliberately unsupported. Matching names at one
indent level would also match struct fields, and a struct field read as a type
declaration is the invented symbol these patterns exist to prevent.

One bug in the measurement tool, found by the same instinct that has paid off
twice today: gin reported zero cross-directory imports, which was too clean.
`measure_boundary_reach` called `import_to_dir` without a suffix, so every Go
module path fell through the TypeScript branch and resolved to nothing. With
the suffix passed, gin goes from 0 to 21 files across 14 edges.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@mick-gsk
mick-gsk merged commit 842b70e into main Jul 29, 2026
12 of 37 checks passed
@mick-gsk
mick-gsk deleted the feat/guard-go branch July 29, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Guard: add Go support, following the TypeScript pattern

2 participants