Skip to content

Commit 11fe5e1

Browse files
committed
docs(requiredstructure): correct extractHeadings caller list in doc comments
checkSync never calls extractHeadings — it receives docHeadings as a parameter. The actual 4th call site (parseSchemaWithRootFS) parses an ephemeral schema-content File built fresh per call, so it doesn't benefit from the memo the way the document-File call sites do. Caught by code review round 1. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BTLNzEVChZtqSc7m7ph5Ah
1 parent 1fdc687 commit 11fe5e1

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

internal/rules/requiredstructure/rule.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,11 +1874,14 @@ type docHeading struct {
18741874
}
18751875

18761876
// extractHeadings walks the AST and collects all headings. Memoized
1877-
// per File via lint.File.MemoFile: a composed schema calls this once
1878-
// per extends source (bodySyncDiagnostics) plus from
1879-
// checkSingleFileSchemaFromData, checkSync, and fixBodySyncIn, so a
1880-
// document referencing N schema sources would otherwise re-walk the
1881-
// same AST N+ times per Check.
1877+
// per File via lint.File.MemoFile: on the document File, this is
1878+
// called from checkSingleFileSchemaFromData, the per-source loop in
1879+
// checkComposedSources (via bodySyncDiagnostics), and fixBodySyncIn,
1880+
// so a document validated against a composed schema with N extends
1881+
// sources would otherwise re-walk the same AST N+ times per Check.
1882+
// parseSchemaWithRootFS also calls this, but on a throwaway
1883+
// schema-content File built fresh per call, so the memo there is a
1884+
// no-op rather than a shared cache.
18821885
func extractHeadings(f *lint.File) []docHeading {
18831886
return f.MemoFile("requiredstructure.docHeadings", buildDocHeadings).([]docHeading)
18841887
}

internal/rules/requiredstructure/rule_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,8 +2006,8 @@ func TestHeadingText_WithLink(t *testing.T) {
20062006
// TestExtractHeadings_Memoized pins that repeated calls on the same
20072007
// File share the same backing slice: a composed schema with N extends
20082008
// sources calls extractHeadings once per source (bodySyncDiagnostics)
2009-
// plus once from checkSingleFileSchemaFromData/checkSync/fixBodySyncIn,
2010-
// so an unmemoized walk re-scans the same AST N+ times per Check.
2009+
// plus once from checkSingleFileSchemaFromData/fixBodySyncIn, so an
2010+
// unmemoized walk re-scans the same AST N+ times per Check.
20112011
func TestExtractHeadings_Memoized(t *testing.T) {
20122012
f := newTestFile(t, "doc.md", "# H1\n\n## H2\n\n### H3\n")
20132013
h1 := extractHeadings(f)

0 commit comments

Comments
 (0)