| id | 2607051920 |
|---|---|
| title | Consolidate duplicated leading-space/blank-line rule helpers into internal/rules/astutil |
| status | ✅ |
| model | sonnet |
| summary | countLeadingSpaces and isBlank/isBlankLine are duplicated, byte-identical, across listindent, orderedlistnumbering, and noreferencestyle. Export one copy from astutil. Flagged by the 2026-07-05 audit. |
Replace the duplicated countLeadingSpaces and
isBlank/isBlankLine helpers in listindent,
orderedlistnumbering, and noreferencestyle with one
shared implementation exported from
internal/rules/astutil.
The 2026-07-05 audit found this duplication:
-
Commit
39a21e63replaced hand-rolled byte loops withbytespackage calls. -
It rewrote the same two helpers identically in three rule packages, shown below.
-
countLeadingSpaces(line []byte) int— identical bodylen(line) - len(bytes.TrimLeft(line, " "))ininternal/rules/listindent/rule.go:184andinternal/rules/orderedlistnumbering/rule.go:378. -
isBlank/isBlankLine(line []byte) bool— identical bodylen(bytes.TrimLeft(line, " \t")) == 0ininternal/rules/orderedlistnumbering/rule.go:290andinternal/rules/noreferencestyle/rule.go:500.
internal/rules/astutil is the doc-sanctioned shared
home for exactly this kind of helper (Go architecture
doc, "rule-to-rule imports" section). A rule package
must not import another rule package, but every rule
package may import astutil. listscan (touched by
the same perf commit) is excluded: its
openingFenceRel isn't duplicated elsewhere, so it
stays as-is.
- Add
CountLeadingSpaces(line []byte, cutset string) intandIsBlank(line []byte, cutset string) bool(or two pairs, one fixed to" "and one to" \t", matching the two call shapes below) tointernal/rules/astutil/astutil.go. - Add dedicated tests in
internal/rules/astutil/astutil_test.go. - In
internal/rules/listindent/rule.go, deletecountLeadingSpaces; call the astutil helper. - In
internal/rules/orderedlistnumbering/rule.go, deletecountLeadingSpacesandisBlank; call the astutil helpers. - In
internal/rules/noreferencestyle/rule.go, deleteisBlankLine; call the astutil helper. go build ./...passes.go test ./internal/rules/listindent/... ./internal/rules/orderedlistnumbering/... ./internal/rules/noreferencestyle/... ./internal/rules/astutil/...passes.- Confirm the allocation-budget test
(
internal/integration/alloc_budget_test.go) still passes for all three rules.
-
internal/rules/astutilexports the shared leading-space and blank-line helpers, each with a dedicated test. -
listindent,orderedlistnumbering, andnoreferencestyleno longer define their own copies. -
go test ./...is green. -
mdsmith check .is green.