Skip to content

fix(rules): links/anchor-text evaluates links per target, not per link - #111

Merged
nc9 merged 1 commit into
mainfrom
loop/104-links-anchor-text-counts-per-link-not-pe
Aug 19, 2026
Merged

nc9 merged 1 commit into
mainfrom
loop/104-links-anchor-text-counts-per-link-not-pe

Conversation

@nc9

@nc9 nc9 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Closes #104

links/anchor-text used to score every <a> tag independently, so the standard card pattern (image link + headline link + "Read more" link, all pointing at the same target) produced two findings even though the headline already names the destination.

This groups a page's outgoing links by resolved target URL and evaluates the group: a target passes if any member carries a descriptive accessible name (text, image alt, aria-label, aria-labelledby, title, or an accessible SVG name).

Acceptance Criteria

  • links/anchor-text groups a page's outgoing links by resolved target URL before evaluating
  • A target group is reported as empty-anchor only when NO link in the group carries any accessible name
  • A target group is reported as generic-anchor only when EVERY link in the group has generic text
  • Findings are deduplicated per target: one card produces at most one item
  • Fixture: card with image/headline/"Read more" links to the same URL — no findings
  • Fixture: single empty-alt image link with no sibling — still reported as empty-anchor
  • Fixture: card where all three links are empty or generic — reported once, not three times
  • Existing tests updated, regression test asserts multi-link card yields zero findings
  • Docs rule page for links/anchor-text updated in docs/

Test plan

  • bun run typecheck (packages/rules)
  • bun test tests (packages/rules) — new tests/anchor-text.test.ts covers the grouping logic

Note: this sandboxed session could not execute bun directly (blocked by session permissions), so tests were written and reasoned through but not run locally — CI should verify.

#104)

Groups a page's outgoing links by resolved target URL before flagging
empty/generic anchor text. Card patterns (image link + headline link +
'Read more', all to the same target) pass as long as one member of the
group carries a descriptive accessible name — matches the SEO intent of
the rule instead of penalizing the recommended redundant-link pattern.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 merged commit 4a83ff0 into main Aug 19, 2026
14 checks passed
@nc9
nc9 deleted the loop/104-links-anchor-text-counts-per-link-not-pe branch August 19, 2026 09:11
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.

links/anchor-text counts per link, not per (source, target) pair — fires on every card

1 participant