Skip to content

fix(rules): respect identical-link context - #1134

Merged
nc9 merged 2 commits into
squirrelscan:mainfrom
WilliamK112:codex/identical-link-context-1043
Oct 26, 2026
Merged

nc9 merged 2 commits into
squirrelscan:mainfrom
WilliamK112:codex/identical-link-context-1043

Conversation

@WilliamK112

Copy link
Copy Markdown
Contributor

Summary

  • group repeated link text by its nearest programmatic section context
  • read context from aria-labelledby, aria-label, or a parent list item's leading link
  • preserve warnings when equal text in equal or absent context points to different destinations
  • cover the reported mega-menu and each accepted context source with focused tests

Closes #1043.

Verification

  • bun test packages/rules/tests (7,612 pass, 25 todo, 0 fail)
  • bun run --filter @squirrelscan/rules typecheck
  • bun run docs:check
  • oxfmt --check and oxlint on the changed rule and test

Checklist

  • I added or updated tests for behavioral changes.
  • I did not include secrets, customer data, or incompatible third-party material.
  • Every commit includes a DCO Signed-off-by line (git commit -s).

Docs: updated the identical-links-same-purpose rule page. Skill: none.

@WilliamK112
WilliamK112 force-pushed the codex/identical-link-context-1043 branch 2 times, most recently from 8e77d9b to e62a8d5 Compare October 26, 2026 07:35
@nc9

nc9 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Thanks @WilliamK112, the grouping by programmatic context is the right model for #1043, the reported mega-menu passes, and the docs and tests read well. One blocker before merge, a performance one:

linkContext walks up to 64 ancestors for every link and resolves aria-labelledby with doc.getElementById (up to 8 ids) at each ancestor that has it, again for every link. In linkedom getElementById is a linear scan, so the cost is links x ids x page size. I measured a page with 5,000 links under one wrapper carrying aria-labelledby and eight ids: the rule took about 22.9 s here (main: a few ms), far past the 2 s rule time budget. Pages with a labelled landmark around a large link list (a footer or a catalogue) are common enough.

Please memoize per ancestor so each distinct element's context is computed once per page, for example a Map<Element, string> of resolved aria-labelledby/aria-label text consulted before the lookup (and cache the li leading-link label the same way). A test with a few thousand links under one aria-labelledby ancestor that asserts a loose time bound, or just checks it completes, would lock it in. The same 5,000 links without a labelled ancestor took about 40 ms, so the rest of the change is fine.

Everything else is non-blocking: CHANGELOG, rule page, DCO and the 5 tests are in order.

@WilliamK112
WilliamK112 force-pushed the codex/identical-link-context-1043 branch from e62a8d5 to 3bd12a2 Compare October 26, 2026 09:38
@WilliamK112

Copy link
Copy Markdown
Contributor Author

Addressed in ed13564: each ancestor aria-labelledby or aria-label context is now memoized once per page, and the parent-list-item leading-link context is cached in the same entry. I added a regression with 5,000 links under one wrapper carrying eight aria-labelledby ids; it completes in about 50 ms locally, and all 6 focused tests complete in 333 ms. The focused tests, rules typecheck, formatting, lint, and diff checks pass. CI is rerunning on the pushed commit.

@nc9
nc9 force-pushed the codex/identical-link-context-1043 branch from ed13564 to ef77552 Compare October 26, 2026 23:29
@nc9
nc9 merged commit 10220e7 into squirrelscan:main Oct 26, 2026
15 checks passed
@nc9

nc9 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Merged. Thank you @WilliamK112, memoizing the aria-labelledby context per ancestor with a 5,000-link regression turned a 22 second worst case into about 10 ms, and the labelled mega-menu from the issue now passes. (Nik)

nc9 added a commit that referenced this pull request Oct 27, 2026
* origin/main:
  feat(rules): broken-link rules are reliability findings with a Reliability badge (#856)
  fix(rules): respect identical-link context (#1134)

Signed-off-by: Nik Cubrilovic <[email protected]>
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.

a11y/identical-links-same-purpose flags mega-menu links whose section context differs

2 participants