Skip to content

feat(linter): warn when data-cite targets a spec available in xref#5295

Draft
marcoscaceres wants to merge 4 commits into
mainfrom
feat/3561-data-cite-xref-linter
Draft

feat(linter): warn when data-cite targets a spec available in xref#5295
marcoscaceres wants to merge 4 commits into
mainfrom
feat/3561-data-cite-xref-linter

Conversation

@marcoscaceres

Copy link
Copy Markdown
Contributor

Closes #3561

New linter rule "prefer-xref" that warns when an author uses data-cite="SPEC#fragment" for a spec that is already in the configured xref database. The xref shorthand syntax is shorter, version-agnostic, and lets ReSpec verify the term exists. Supports error severity via lint config.

When conf.xref is configured with a named profile (e.g. "web-platform")
or an explicit spec list, authors sometimes write data-cite="SPEC#frag"
for terms that xref could resolve automatically. This is fragile because
fragment identifiers change between spec versions.

The new prefer-xref linter rule detects a[data-cite*="#"] and
dfn[data-cite*="#"] where the spec key matches a spec in the configured
xref list, and warns with a hint to use [= term =] or {{ IDL }}
shorthand instead. Elements with class="lint-ignore" are excluded.

The check is opt-in (lint: { "prefer-xref": true }) and skips when
xref: true is set (no specific spec list — would need a network call
to determine coverage).

Closes #3561
- Import profiles from xref.js instead of duplicating the constant
- Add error severity support (conf.lint["prefer-xref"] = "error")
- Merge falsy and true xref guards into single early return
- Remove dead ?? "" fallback (selector guarantees data-cite exists)
- Remove unnecessary ?. on Map.get() after guaranteed set
- Trim verbose JSDoc to essential type annotations

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new linter rule to discourage using data-cite="SPEC#fragment" when the cited spec is covered by the configured xref dataset, encouraging the shorter xref/shorthand approach.

Changes:

  • Introduces core/linter-rules/prefer-xref and wires it into the W3C profile build.
  • Exposes xref profile lists from core/xref so the linter can reuse them.
  • Adds a dedicated spec suite covering most configuration and matching scenarios.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/spec/core/linter-rules/prefer-xref-spec.js New tests for the prefer-xref linter rule behavior across xref/lint configurations.
src/core/xref.js Exports profiles so other modules (like lints) can reuse the configured profile spec lists.
src/core/linter-rules/prefer-xref.js New linter rule implementation that finds data-cite fragments pointing at specs in the configured xref set and emits grouped warnings/errors.
profiles/w3c.js Registers the new linter rule in the W3C build pipeline.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/core/linter-rules/prefer-xref.js
Comment thread src/core/linter-rules/prefer-xref.js
Comment thread src/core/linter-rules/prefer-xref.js
Comment thread src/core/linter-rules/prefer-xref.js Fixed
…tion

- Register prefer-xref in geonovum, aom, and dini profiles
- Add Czech (cs) localization for msg and hint strings
Comment thread src/core/linter-rules/prefer-xref.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants