Skip to content

refactor(scripts): walk the AST with estree-walker in arch-lint - #561

Merged
Vivswan merged 1 commit into
mainfrom
refactor/arch-lint-estree-walker
Oct 27, 2026
Merged

Vivswan merged 1 commit into
mainfrom
refactor/arch-lint-estree-walker

Conversation

@Vivswan

@Vivswan Vivswan commented Oct 26, 2026

Copy link
Copy Markdown
Owner

What this changes

nodesOf, a hand-rolled recursive generator  ->  estree-walker's walk(), through a six-line typed adapter

differential, old against new, visit order as (type, start, end):
  536 repository files        584,305 nodes    0 mismatches
  5,000 generated modules     258,520 nodes    0 mismatches (977 refused by both, same message)
negative control: an injected text -> problem import is refused identically

How

  • The adapter exists because walk() is typed to estree's Node with no generic, so the oxc program crosses that boundary with one cast, the pattern refusal-messages.test.ts already uses.
  • importSpecifiers passes its body as the visit callback; every thrown message is unchanged.
  • Library: estree-walker 3.0.3, already a declared devDependency, covers the walk.

Proof

  • Tests: arch-lint, gen-docs, and docs-registry suites, 88 pass; bun run lint:arch gives the same verdict.
  • Gates: typecheck, fleet biome 0, member-shape 0, line cap.
Technical details
  • Recorded, not built: oxc-parser 0.152 ships a typed Visitor (a per-node-type handler table, no casts); it would restructure isModuleLoad's switch into handler keys.
  • Files: .github/scripts/arch-lint.ts.

arch-lint.ts walked the oxc-parser tree with a hand-rolled recursive generator, nodesOf, that descended every object and array for anything carrying a string `type`. estree-walker, already a declared devDependency, does that walk: it ducktypes children by their `type` field, so oxc's TypeScript nodes walk like the ESTree ones. Only its estree-typed signature needs a cast, at the one call.

The differential check ran the old walk, importSpecifiers, and lintArchitecture against the new over every .ts file under src/, test/, and .github/scripts/ (536 files, 584,305 nodes in visit order) and over 5,000 seeded generated modules covering every import form the tests list, in nested positions, with computed specifiers and non-parsing files. Node sequences, specifier lists, and refusal messages were identical throughout.

lintArchitecture gives the same empty verdict on the repository, and the same single forbidden-import line on a scratch copy of src/ with an undeclared text -> problem import injected.
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 has no identified blocking defects, with existing coverage and reported differential checks supporting behavior preservation.

No open issues 🎉

What changed in this PR

Replaces arch-lint's custom recursive AST traversal with estree-walker, simplifying import analysis without changing its intended behavior.

Changes:

  • Adds a typed adapter between oxc-parser nodes and estree-walker.
  • Converts import collection to a visit callback, preserving filtering and refusal messages.
File Description
.github/​scripts/​arch-lint.ts Replaces nodesOf with the eachNode adapter and updates import collection.

Review effort: Balanced

@Vivswan
Vivswan marked this pull request as ready for review October 26, 2026 20:19
@Vivswan
Vivswan merged commit 21aaf30 into main Oct 27, 2026
31 checks passed
@Vivswan
Vivswan deleted the refactor/arch-lint-estree-walker branch October 27, 2026 07:19
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