Skip to content

Ambiguous reference anchors are undetected (two headings that slug identically) #106

Description

@aslakhellesoy

Follow-up to #104 (ADR 0016).

ADR 0016 lists ambiguous anchor as an authoring error: two headings in one file that slug identically (## Setup twice → #setup and #setup-1 on GitHub). It is not implemented.

Why

Sections resolve through the scope stack: a candidate belongs to a section iff the section's slug appears in its scopeStack. That was a deliberate deviation — it means "from this heading until the next of the same or higher level" is already computed, and no headings field had to be added to Doc, which kept every port's doc.json golden untouched.

The cost is exactly this: two same-slug headings are indistinguishable that way, so a reference to #setup silently pulls in the candidates of both sections, in document order.

Options

  1. Lint rule (reference/lint.md): a file containing a referenced section must have unique heading slugs. Cheap, local, catches it at authoring time — but only for people who run lint.
  2. Add headings to Doc and resolve sections against the real outline. Correct at the source and enables a precise reference-ambiguous-anchor diagnostic, at the cost of a new AST field and regenerating doc.json across seven ports.

(1) is probably enough: duplicate headings in a shared-section file are rare and obviously bad. Worth deciding explicitly rather than leaving the ADR's Errors list out of sync with what the code does.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions