Skip to content

refactor(scripts): walk the markdown tree with unist-util-visit-parents in generated-regions - #562

Merged
Vivswan merged 1 commit into
mainfrom
refactor/generated-regions-visit-parents
Oct 27, 2026
Merged

Vivswan merged 1 commit into
mainfrom
refactor/generated-regions-visit-parents

Conversation

@Vivswan

@Vivswan Vivswan commented Oct 26, 2026

Copy link
Copy Markdown
Owner

What this changes

scanMarkdown's walk(node, inQuote) closure  ->  visitParents(tree, visitor), inQuote = ancestors.some(blockquote)

differential, old against new, the full scan result:
  53 repository markdown files      4,628 spans + 400 headings      0 mismatches
  5,000 generated documents        25,289 spans + 3,879 headings    0 mismatches
  (fences, HTML blocks, quotes three deep, GFM tables, markers inside code spans, 30% CRLF)

How

  • Typed through the library's BuildVisitor<Root>, no cast.
  • Library: unist-util-visit-parents 6.0.2 becomes a direct devDependency; it was already transitive through mdast-util-to-markdown.

Proof

  • Tests: test/scripts 546 pass; config, library, and docs suites 380 pass; bun run build:check finds all 14 generated files unchanged.
  • Gates: typecheck, fleet biome 0, member-shape 0, knip, line cap.
Technical details
  • Dependency: package.json and bun.lock gain one line each; the public-surface branch adds the identical line, so whichever lands second rebases over an identical change.
  • Recorded, not built: yamlComments in the same file walks the yaml CST by hand; yaml's CST.visit visits collection items, not tokens, so it is not a fit.
  • Files: .github/scripts/lib/generated-regions.ts, package.json, bun.lock.

…nist-util-visit-parents

scanMarkdown in generated-regions.ts walked the mdast tree with a hand-rolled recursive closure that pushed each node's span by type, recorded the headings outside every blockquote through an inQuote flag it threaded down, and recursed into children by hand. unist-util-visit-parents does that walk, preorder with the ancestor list at every node, so the flag becomes a check of the ancestors. It was a transitive dependency of the mdast stack; it is now a direct devDependency at the version bun.lock already held.

The differential check ran the old scan against the new over every markdown file in the repository (53 files: 4,628 spans and 400 headings) and over 5,000 seeded generated documents built from 46 block shapes, nested blockquotes, unclosed fences and raw blocks, GFM tables, CRLF endings, and markers in every position the placement check classifies (25,289 spans and 3,879 headings). Every span list and heading agreed. bun run build:check finds all 14 generated files placed as before.
Copilot AI balanced review requested due to automatic review settings October 26, 2026 20:13
@github-actions

Copy link
Copy Markdown
Contributor

File size check

0 over a hard cap (fails), 6 warning(s).

File Size Tier Cap
src/engine/diff.ts:56 11 comment lines warn 10
src/github/api-error.ts:9 11 comment lines warn 10
src/problem.ts:73 18 comment lines warn 10
src/sections/contract/errors.ts:13 11 comment lines warn 10
src/sections/contract/module.ts:55 12 comment lines warn 10
src/sections/shared/list/decl.ts:265 14 comment lines warn 10

Split the file, wrap the line, shorten or exempt the comment, or list the path in .file-size-allow.local with a # reason.

5 managed file(s) skipped; repo-platform owns them.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused refactor preserves traversal behavior, keeps dependency declarations consistent, and has no identified blocking issues.

No open issues 🎉

What changed in this PR

Replaces the handwritten Markdown tree walker in generated-region scanning with unist-util-visit-parents, preserving span collection and excluding quoted headings.

Changes:

  • Uses ancestor-aware traversal to identify headings outside blockquotes.
  • Declares the existing transitive library as a pinned direct development dependency.
File Description
package.json Adds unist-util-visit-parents 6.0.2 as a development dependency.
bun.lock Records the matching direct dependency.
.github/​scripts/​lib/​generated-regions.ts Replaces recursive traversal with visitParents and ancestor-based blockquote filtering.

Review effort: Balanced

@Vivswan
Vivswan marked this pull request as ready for review October 26, 2026 20:18
@Vivswan
Vivswan merged commit 1883231 into main Oct 27, 2026
31 checks passed
@Vivswan
Vivswan deleted the refactor/generated-regions-visit-parents branch October 27, 2026 07:17
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.

2 participants