Skip to content

build(docs): check local links with remark-validate-links (#1041) - #1044

Closed
jimhoyd wants to merge 1 commit into
mainfrom
claude/standard-link-check
Closed

jimhoyd wants to merge 1 commit into
mainfrom
claude/standard-link-check

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

Part of #1041 (item 4).

scripts/check-local-links.ts no longer owns a Markdown link parser, a GitHub heading slugger or a fragment resolver. Those now come from remark-validate-links (MIT), run through unified-engine with repository: false. That setting means it runs no git remote and makes no network request. The script keeps only the rules a generic tool can't express. It still runs in npm run check:docs.

Where each existing rule went

Current rule Now
dead-relative-link (relative target missing on disk) tool (missing-file, reported as dead-relative-link)
dead-fragment: GitHub heading slugs, -1/-2 for repeated headings, setext headings, headings in fenced code ignored tool (github-slugger, reported as dead-fragment)
dead-fragment: explicit <a id> / <a name> anchors residual: a pre-pass sets hProperties.id on the html node, which the tool then counts
fragments checked only on .md targets (file.ts#L10 and directory fragments skipped); percent-encoded fragments decoded residual (in the pre-pass that rewrites links)
pinned blob/v<current> and tree/v<current> links checked against the checkout; other versions and other sites skipped residual: the link is rewritten to a checkout path, and the tool checks it
shipped-link: blob/main/tree/main, or a path outside the package, in a file a package ships residual
retired-repository (jimhoyd-com/urlcode-<package>) residual
local-issue-tracker (issues/, backlog/, ISSUES.md, BACKLOG.md) residual
<!-- local-links: historical --> (line or paragraph) and historical-file residual: filters every message, the tool's included
walk: every authored .md plus root llms.txt, skipping node_modules/dist/build/coverage/dotted dirs residual

Changes in behaviour. Links are now read from the Markdown syntax tree, not by a regex over each line. Three things follow:

  • Links inside code blocks and code spans are no longer checked.
  • Links with a title ([a](x.md "t")) are now checked.
  • Fragment matching ignores case, as the tool does.

The retired-repository rule still scans raw lines, as before. On this checkout, both old and new versions pass. The new version counts 155 files, 1306 relative links and 748 fragments. The old one counted 155, 1297 and 744: the extra 9 links and 4 fragments are titled links that the old regex skipped.

Tests ported

The unit tests of the owned slugger (githubSlug, headingText, markdownAnchors) are now fixture checkouts run through checkLinks. They cover the same cases: slugs, repeated headings, explicit anchors, setext headings and fenced code. New fixture cases cover these rules, which were previously checked only against the live checkout:

  • dead relative links;
  • pinned current-version and other-version links;
  • retired repositories;
  • historical line, paragraph and file markers;
  • local issue trackers;
  • shipped links.

The shippedLinkProblem/pinnedRepositoryPath tests are unchanged. test/docs-url.test.ts now checks core's docsUrl links by running them through checkLinks instead of markdownAnchors.

One old case is dropped: the Safe <scr<b>ipt>heading tag-stripping case. It tested the owned sanitizer, which is removed. The tool slugs from mdast text with HTML excluded.

Measure

  • scripts/check-local-links.ts: 349 → 162 lines (+122 / −309). That is more than the ~80 estimated. The rule logic is about 80 lines; the rest is the engine wiring, the file walk and a 27-line header documenting the rules.
  • Tests: test/doc-checks.test.ts +50 / −29; test/docs-url.test.ts +7 / −8.
  • CONTRIBUTING.md: +4 / −1 (names the tool and the residual rules).
  • Dev dependencies, pinned exactly: [email protected], [email protected], [email protected], [email protected]. vfile is declared only because the script and tests import it; it adds no lockfile entries.
  • Lockfile cost: 166 packages entries added (201 → 367). No existing entry changed or was removed, and package-lock.json grew by 2,395 lines. Most of the added entries come from unified-engine, which remark-validate-links itself depends on: @npmcli/config, glob, load-plugin, the micromark family and others.

Verification

  • npm run verify passes locally (lint, both typechecks, check:docs, build, full tests, workspaces).
  • A virtual file with [a](GONE.md) and [b](docs/HTTP.md#nope) reports dead-relative-link and dead-fragment.

Not done: docs/FRAMEWORK.md "Ownership" is not edited, as instructed.

🤖 Generated with Claude Code

Replace the owned Markdown parser, heading slugger and fragment resolver in
scripts/check-local-links.ts with remark-validate-links, run offline through
unified-engine (repository: false). The script keeps only the URLCode rules:
retired repositories, local issue trackers, shipped package links, pinned
blob/tree v<current version> links, explicit <a id> anchors, Markdown-only
fragments and the historical markers. Tests are ported to fixture checkouts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd enabled auto-merge (squash) September 30, 2026 13:26
@jimhoyd
jimhoyd disabled auto-merge September 30, 2026 13:26
@jimhoyd

jimhoyd commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator Author

Closed by owner decision (#1041): the swap removed ~190 lines of owned code but added 166 dev packages (~2,400 lockfile lines). Too lopsided for a docs check; the owned checker stays.

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.

1 participant