Repository navigation
feat(rules): add links/broken-anchors for in-page anchor links - #718
Conversation
|
Review of links/broken-anchors. I read the diff and checked that (low) (low) (nit) (nit) (nit) Test coverage: the golden test is good for engine parity. I could not confirm unit coverage for percent-encoded fragments, the I found no critical or high issues. The logic looks correct and conservative: it skips 4xx/5xx and unfetched targets, handles truncation, and treats unrendered client shells as unconfirmed. The docs and registration look consistent. |
Maintainer review (2026-10-12)Verdict: needs fixes (low). I reviewed head 6c7950b against main 2dca3b9. Main CI is green at that sha, so the red checks here come from this PR. Acceptance criteria (#706)All 11 are met. Fixes
PR hygiene
Merge orderThis PR merges second, after #714. #720 conflicts with it in |
Auto-review did not completeThe
Partial findings recovered from the session (incomplete, unverified, and NOT a merge signal): Show partial reviewYou've hit your session limit · resets 10:10pm (UTC) |
A link to #pricing, or to /page#pricing, whose target id is gone still loads, and the reader lands at the top of the page. links/broken-anchors warns when a fragment names no id or <a name> on its target page, reports an unrendered client-side shell as unconfirmed (info), and labels broken skip links. The cross-page check needs each crawled page's ids. The streaming engine drops each DOM after the page pass, so the ids are collected page-time into a capped per-page record (collected-signals.ts). The v1 engine builds the same record from the DOM through the same extractor (links/page-anchors.ts), so both engines judge identical records. SiteData pages carry `rendered` so the v1 path can tell an unrendered shell from a rendered one. - Each finding's linking pages are a Set, so a nav link repeated across a large site costs one insert per link, not a scan of every page so far. - A streaming snapshot cached before the anchor record existed (no page has the field) is skipped with a --refresh hint instead of passing with zero links. - Purely numeric fragments (#0, #1) are template do-nothing links and are not judged. - The skip-link text heuristic is shared with a11y/skip-link (hasSkipLinkText), beside the shared SKIP_LINK_SELECTOR. No network requests: the rule reads only what the crawl already fetched. Golden gate: 101737 -> 101738 findings and 302 -> 303 tally rows on main with #703 (one whole-crawl check, a pass on the synthetic site); healthScore.overall stays 51. Signed-off-by: Nik Cubrilovic <[email protected]>
7b897c1 to
6408959
Compare
|
Review of
Security: no concerns. The rule does no network I/O and only reads already-parsed DOM, and the per-page record is capped, so memory stays bounded. |
Summary
Adds the
links/broken-anchorsrule. A link to#pricing, or to/page#pricing, whose target id no longer exists still loads, and the reader lands at the top of the page. The rule warns when a fragment names noidor<a name>on its target page.#fraglink is judged against the page's own ids./page#fraglink is judged against that page's ids. A target that was not fetched, or answered 4xx/5xx, is left tolinks/broken-links.(skip link).a11y/skip-linkkeeps its verdict. Its selector is now exported and shared, with no change to its logic.#and#top, purely numeric fragments (#0,#1, template do-nothing links), hash routes and state (#/x,#!x,#k=v), text fragments (#:~:), links to uncrawled or error pages, and targets over the id cap.--refreshhint, never as a pass with zero links judged.Streaming parity. The streaming engine drops each page's DOM after the page pass, so the ids cannot be read later. Each page's distinct ids,
<a name>values, same-page fragments and skip-link fragments are collected page-time into a capped record (collected-signals.ts,links/page-anchors.ts). The v1 engine builds the same record from the DOM through the same extractor. Therenderedflag rides on the site-page entries so both engines make the same unconfirmed call. The per-page record is capped at 512 ids and 256 same-page fragments, so memory stays bounded on large crawls.Changes from the maintainer review (2026-10-12):
streaming-rules-canonical-golden.test.ts101737 -> 101738 findings and 302 -> 303 tally rows, with comments; the rule's tally row is pinned (one pass on the synthetic site).healthScore.overallstays 51.{count} in-page anchor link(s) ...), and list the numeric-fragment exclusion and the cached-snapshot skip.Set(wasArray.includesper link: O(sources^2) for a site-wide nav link).a11y/skip-link(hasSkipLinkText) and shared, besideSKIP_LINK_SELECTOR.finalKeytosourceKey).[Unreleased]/### Added.Agent skill: yes, the squirrelscan agent skill (squirrelscan/skills) should learn the new rule; the maintainer files that as a private issue. Per-category counts (Links 15 -> 16) are left for the maintainer's batched docs PR.
Closes #706
Verification
The new rule, extractor and test files are oxfmt-clean and oxlint-clean (the rules package has no format or lint script of its own).
Notes for review:
#xsame-page links oridattributes, so the same-page DOM path is covered by the rule-level parity test inbroken-anchors.test.ts, not by the seeded crawl.renderedflag on the fixture, not by a browser-rendered audit.Acceptance checklist (#706)
<a href="#pricing">and no element withid="pricing"produces a warning naming the link, the fragment and the page<section id="pricing">, or with<a name="pricing">, produces no finding/b#install, page B is crawled and has noid="install": one warning naming/b#installand listing page A as a source/#pricingand the homepage has noid="pricing": one finding listing the five source pages, not five findingshref="#",#top(with noid="top"on the page),#/settings,#!/home,#access_token=abcand#:~:text=helloproduce no finding/c#xwhere/cwas not crawled, or answered 404, produces no finding from this rule#caf%C3%A9findsid="café"), and#Pricingdoes not matchid="pricing"/app#settingswhere/appis an empty client-rendered shell (<div id="root"></div>plus a script) is reported as unconfirmed (info), not as a warning#main-contentis reported once, by this rule, and labelled as a skip link; thea11y/skip-linkverdict for that page is unchangeddocs/rules/links/Checklist
Signed-off-byline (git commit -s).