Repository navigation
refactor(scripts): walk the markdown tree with unist-util-visit-parents in generated-regions - #562
Merged
Merged
Conversation
…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.
Contributor
File size check0 over a hard cap (fails), 6 warning(s).
Split the file, wrap the line, shorten or exempt the comment, or list the path in 5 managed file(s) skipped; repo-platform owns them. |
There was a problem hiding this comment.
🟢 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
How
BuildVisitor<Root>, no cast.unist-util-visit-parents6.0.2 becomes a direct devDependency; it was already transitive through mdast-util-to-markdown.Proof
bun run build:checkfinds all 14 generated files unchanged.Technical details
package.jsonandbun.lockgain one line each; the public-surface branch adds the identical line, so whichever lands second rebases over an identical change.yamlCommentsin the same file walks the yaml CST by hand; yaml'sCST.visitvisits collection items, not tokens, so it is not a fit..github/scripts/lib/generated-regions.ts,package.json,bun.lock.