feat(linter): warn when data-cite targets a spec available in xref#5295
Draft
marcoscaceres wants to merge 4 commits into
Draft
feat(linter): warn when data-cite targets a spec available in xref#5295marcoscaceres wants to merge 4 commits into
marcoscaceres wants to merge 4 commits into
Conversation
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
Contributor
There was a problem hiding this comment.
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-xrefand wires it into the W3C profile build. - Exposes xref profile lists from
core/xrefso 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.
…tion - Register prefer-xref in geonovum, aom, and dini profiles - Add Czech (cs) localization for msg and hint strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.