Skip to content

Commit

Permalink
feat(lint): set mdn_url via unambiguously related browser-compat
Browse files Browse the repository at this point in the history
…frontmatter keys (#25563)

The way this works is as follows:

1. take the whole MDN content inventory,
2. group all pages by BCD feature:
    - using the features referenced in the `browser-compat` frontmatter,
    - ignoring slug/feature combinations that don't "match" (i.e. one of their tails should contain the other)
3. overwrite the `mdn_url` accordingly (unless the current url contains a fragment).
  • Loading branch information
caugner authored Jan 8, 2025
1 parent 9ac62c5 commit e6044d5
Show file tree
Hide file tree
Showing 52 changed files with 257 additions and 84 deletions.
2 changes: 2 additions & 0 deletions api/CredentialsContainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@
"extensions": {
"__compat": {
"description": "`create()` extensions",
"mdn_url": "https://developer.mozilla.org/docs/Web/API/Web_Authentication_API/WebAuthn_extensions",
"spec_url": "https://w3c.github.io/webauthn/#dom-publickeycredentialcreationoptions-extensions",
"tags": [
"web-features:webauthn"
Expand Down Expand Up @@ -1006,6 +1007,7 @@
"extensions": {
"__compat": {
"description": "`get()` extensions",
"mdn_url": "https://developer.mozilla.org/docs/Web/API/Web_Authentication_API/WebAuthn_extensions",
"spec_url": "https://w3c.github.io/webauthn/#dom-publickeycredentialrequestoptions-extensions",
"tags": [
"web-features:webauthn"
Expand Down
2 changes: 1 addition & 1 deletion api/HTMLCanvasElement.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"contextlost_event": {
"__compat": {
"description": "`contextlost` event",
"mdn_url": "https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement/webglcontextlost_event",
"mdn_url": "https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement/contextlost_event",
"spec_url": "https://html.spec.whatwg.org/multipage/indices.html#event-contextlost",
"tags": [
"web-features:canvas-context-lost"
Expand Down
2 changes: 1 addition & 1 deletion api/HTMLDetailsElement.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"name": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/API/HTMLDetailsElement/open",
"mdn_url": "https://developer.mozilla.org/docs/Web/API/HTMLDetailsElement/name",
"spec_url": "https://html.spec.whatwg.org/multipage/interactive-elements.html#dom-details-name",
"tags": [
"web-features:details-name"
Expand Down
116 changes: 116 additions & 0 deletions api/RTCStatsReport.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions api/Selection.json
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@
"empty": {
"__compat": {
"description": "`empty()` as alias of `removeAllRanges()`",
"mdn_url": "https://developer.mozilla.org/docs/Web/API/Selection/removeAllRanges",
"mdn_url": "https://developer.mozilla.org/docs/Web/API/Selection/empty",
"spec_url": "https://w3c.github.io/selection-api/#dom-selection-removeallranges",
"tags": [
"web-features:selection-api"
Expand Down Expand Up @@ -1306,7 +1306,7 @@
"setPosition": {
"__compat": {
"description": "`setPosition()` as alias of `collapse()`",
"mdn_url": "https://developer.mozilla.org/docs/Web/API/Selection/collapse",
"mdn_url": "https://developer.mozilla.org/docs/Web/API/Selection/setPosition",
"spec_url": "https://w3c.github.io/selection-api/#dom-selection-collapse",
"tags": [
"web-features:selection-api"
Expand Down
10 changes: 5 additions & 5 deletions api/WebGL2RenderingContext.json
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@
},
"bufferData": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/bufferData",
"mdn_url": "https://developer.mozilla.org/docs/Web/API/WebGL2RenderingContext/bufferData",
"spec_url": "https://registry.khronos.org/webgl/specs/latest/1.0/#5.14.5",
"tags": [
"web-features:webgl2"
Expand Down Expand Up @@ -927,7 +927,7 @@
},
"bufferSubData": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/bufferSubData",
"mdn_url": "https://developer.mozilla.org/docs/Web/API/WebGL2RenderingContext/bufferSubData",
"spec_url": "https://registry.khronos.org/webgl/specs/latest/1.0/#5.14.5",
"tags": [
"web-features:webgl2"
Expand Down Expand Up @@ -1715,7 +1715,7 @@
},
"compressedTexImage3D": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/compressedTexImage2D",
"mdn_url": "https://developer.mozilla.org/docs/Web/API/WebGL2RenderingContext/compressedTexImage3D",
"spec_url": "https://registry.khronos.org/webgl/specs/latest/2.0/#3.7.6",
"tags": [
"web-features:webgl2"
Expand Down Expand Up @@ -3389,7 +3389,7 @@
},
"drawingBufferColorSpace": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/drawingBufferColorSpace",
"mdn_url": "https://developer.mozilla.org/docs/Web/API/WebGL2RenderingContext/drawingBufferColorSpace",
"spec_url": "https://registry.khronos.org/webgl/specs/latest/1.0/#DOM-WebGLRenderingContext-drawingBufferColorSpace",
"tags": [
"web-features:webgl2-color-management"
Expand Down Expand Up @@ -8674,7 +8674,7 @@
},
"uniformMatrix2fv": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/API/WebGLRenderingContext/uniformMatrix",
"mdn_url": "https://developer.mozilla.org/docs/Web/API/WebGL2RenderingContext/uniformMatrix",
"spec_url": "https://registry.khronos.org/webgl/specs/latest/1.0/#5.14.10",
"tags": [
"web-features:webgl2"
Expand Down
2 changes: 1 addition & 1 deletion api/WorkerNavigator.json
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
},
"hardwareConcurrency": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/API/Navigator/hardwareConcurrency",
"mdn_url": "https://developer.mozilla.org/docs/Web/API/WorkerNavigator/hardwareConcurrency",
"spec_url": "https://html.spec.whatwg.org/multipage/workers.html#dom-navigator-hardwareconcurrency-dev",
"tags": [
"web-features:hardware-concurrency"
Expand Down
3 changes: 3 additions & 0 deletions css/at-rules/font-palette-values.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
},
"base-palette": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/@font-palette-values/base-palette",
"spec_url": "https://drafts.csswg.org/css-fonts/#base-palette-desc",
"tags": [
"web-features:font-palette"
Expand Down Expand Up @@ -78,6 +79,7 @@
},
"font-family": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/@font-palette-values/font-family",
"spec_url": "https://drafts.csswg.org/css-fonts/#font-family-2-desc",
"tags": [
"web-features:font-palette"
Expand Down Expand Up @@ -115,6 +117,7 @@
},
"override-colors": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/@font-palette-values/override-colors",
"spec_url": "https://drafts.csswg.org/css-fonts/#override-color",
"tags": [
"web-features:font-palette"
Expand Down
1 change: 1 addition & 0 deletions css/at-rules/import.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"layer": {
"__compat": {
"description": "`layer()`",
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/@import/layer_function",
"spec_url": "https://drafts.csswg.org/css-cascade-5/#ref-for-typedef-layer-name",
"tags": [
"web-features:cascade-layers"
Expand Down
1 change: 1 addition & 0 deletions css/at-rules/position-try.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"position-try": {
"__compat": {
"description": "`@position-try`",
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/@position-try",
"spec_url": "https://drafts.csswg.org/css-anchor-position-1/#at-ruledef-position-try",
"tags": [
"web-features:anchor-positioning"
Expand Down
1 change: 1 addition & 0 deletions css/at-rules/view-transition.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"view-transition": {
"__compat": {
"description": "`@view-transition`",
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/@view-transition",
"spec_url": "https://drafts.csswg.org/css-view-transitions-2/#view-transition-rule",
"tags": [
"web-features:cross-document-view-transitions"
Expand Down
1 change: 1 addition & 0 deletions css/properties/font-palette.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
"palette-mix_function": {
"__compat": {
"description": "`palette-mix()`",
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/font-palette/palette-mix",
"spec_url": "https://drafts.csswg.org/css-fonts/#typedef-font-palette-palette-mix",
"tags": [
"web-features:font-palette-animation"
Expand Down
2 changes: 1 addition & 1 deletion css/properties/grid-template-columns.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"fit-content": {
"__compat": {
"description": "`fit-content()`",
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/fit-content",
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/fit-content_function",
"spec_url": "https://drafts.csswg.org/css-grid/#funcdef-grid-template-columns-fit-content",
"tags": [
"web-features:grid"
Expand Down
4 changes: 4 additions & 0 deletions css/properties/width.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
},
"fit-content": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/fit-content",
"spec_url": "https://drafts.csswg.org/css-sizing-4/#valdef-width-fit-content",
"tags": [
"web-features:fit-content"
Expand Down Expand Up @@ -192,6 +193,7 @@
"fit-content_function": {
"__compat": {
"description": "`fit-content()`",
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/fit-content_function",
"tags": [
"web-features:fit-content-function"
],
Expand Down Expand Up @@ -273,6 +275,7 @@
},
"max-content": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/max-content",
"spec_url": "https://drafts.csswg.org/css-sizing-3/#valdef-width-max-content",
"tags": [
"web-features:min-max-content"
Expand Down Expand Up @@ -332,6 +335,7 @@
},
"min-content": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/min-content",
"spec_url": "https://drafts.csswg.org/css-sizing-3/#valdef-width-min-content",
"tags": [
"web-features:min-max-content"
Expand Down
1 change: 1 addition & 0 deletions css/selectors/details-content.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"details-content": {
"__compat": {
"description": "`::details-content`",
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/::details-content",
"spec_url": "https://drafts.csswg.org/css-pseudo-4/#details-content-pseudo",
"tags": [
"web-features:details-content"
Expand Down
1 change: 1 addition & 0 deletions css/types/easing-function.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"linear-function": {
"__compat": {
"description": "`linear()`",
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/easing-function/linear",
"spec_url": "https://drafts.csswg.org/css-easing/#the-linear-easing-function",
"tags": [
"web-features:linear-easing"
Expand Down
2 changes: 1 addition & 1 deletion css/types/url.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"url": {
"__compat": {
"description": "`<url>`",
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/url_value",
"mdn_url": "https://developer.mozilla.org/docs/Web/CSS/url_function",
"spec_url": "https://drafts.csswg.org/css-values/#urls",
"tags": [
"web-features:font-face"
Expand Down
1 change: 1 addition & 0 deletions html/elements/a.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@
},
"rel": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/HTML/Attributes/rel",
"spec_url": "https://html.spec.whatwg.org/multipage/links.html#attr-hyperlink-rel",
"tags": [
"web-features:a"
Expand Down
1 change: 1 addition & 0 deletions html/elements/area.json
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@
},
"rel": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/HTML/Attributes/rel",
"spec_url": "https://html.spec.whatwg.org/multipage/links.html#attr-hyperlink-rel",
"tags": [
"web-features:image-maps"
Expand Down
1 change: 1 addition & 0 deletions html/elements/audio.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
},
"crossorigin": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/HTML/Attributes/crossorigin",
"spec_url": "https://html.spec.whatwg.org/multipage/media.html#attr-media-crossorigin",
"tags": [
"web-features:audio"
Expand Down
2 changes: 2 additions & 0 deletions html/elements/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
},
"autocomplete": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/HTML/Attributes/autocomplete",
"spec_url": "https://html.spec.whatwg.org/multipage/forms.html#attr-form-autocomplete",
"tags": [
"web-features:form"
Expand Down Expand Up @@ -425,6 +426,7 @@
},
"rel": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/HTML/Attributes/rel",
"spec_url": "https://html.spec.whatwg.org/multipage/forms.html#attr-form-rel",
"tags": [
"web-features:form"
Expand Down
1 change: 1 addition & 0 deletions html/elements/iframe.json
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,7 @@
},
"credentialless": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/Security/IFrame_credentialless",
"spec_url": "https://wicg.github.io/anonymous-iframe/#attr-iframe-credentialless",
"tags": [
"web-features:iframe-credentialless"
Expand Down
1 change: 1 addition & 0 deletions html/elements/img.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@
},
"crossorigin": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/HTML/Attributes/crossorigin",
"spec_url": "https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-crossorigin",
"tags": [
"web-features:img"
Expand Down
1 change: 1 addition & 0 deletions html/elements/link.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
},
"crossorigin": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/HTML/Attributes/crossorigin",
"spec_url": "https://html.spec.whatwg.org/multipage/semantics.html#attr-link-crossorigin",
"tags": [
"web-features:link"
Expand Down
4 changes: 4 additions & 0 deletions html/elements/script.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
},
"crossorigin": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/HTML/Attributes/crossorigin",
"spec_url": "https://html.spec.whatwg.org/multipage/scripting.html#attr-script-crossorigin",
"tags": [
"web-features:script"
Expand Down Expand Up @@ -562,6 +563,7 @@
},
"type": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/HTML/Element/script/type",
"spec_url": "https://html.spec.whatwg.org/multipage/scripting.html#attr-script-type",
"tags": [
"web-features:script"
Expand Down Expand Up @@ -601,6 +603,7 @@
"importmap": {
"__compat": {
"description": "`type=\"importmap\"`",
"mdn_url": "https://developer.mozilla.org/docs/Web/HTML/Element/script/type/importmap",
"spec_url": "https://html.spec.whatwg.org/multipage/webappapis.html#import-map",
"tags": [
"web-features:import-maps"
Expand Down Expand Up @@ -724,6 +727,7 @@
"speculationrules": {
"__compat": {
"description": "`type=\"speculationrules\"`",
"mdn_url": "https://developer.mozilla.org/docs/Web/HTML/Element/script/type/speculationrules",
"spec_url": "https://wicg.github.io/nav-speculation/speculation-rules.html#speculation-rules-script",
"tags": [
"web-features:speculation-rules"
Expand Down
4 changes: 4 additions & 0 deletions html/elements/textarea.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
},
"autocomplete": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/HTML/Attributes/autocomplete",
"spec_url": "https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-autocomplete",
"tags": [
"web-features:textarea"
Expand Down Expand Up @@ -241,6 +242,7 @@
},
"dirname": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/HTML/Attributes/dirname",
"spec_url": "https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#attr-fe-dirname",
"tags": [
"web-features:dirname"
Expand Down Expand Up @@ -501,6 +503,7 @@
},
"placeholder": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/HTML/Attributes/placeholder",
"spec_url": "https://html.spec.whatwg.org/multipage/form-elements.html#attr-textarea-placeholder",
"tags": [
"web-features:textarea"
Expand Down Expand Up @@ -631,6 +634,7 @@
},
"required": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/HTML/Attributes/required",
"spec_url": "https://html.spec.whatwg.org/multipage/form-elements.html#attr-textarea-required",
"tags": [
"web-features:textarea"
Expand Down
1 change: 1 addition & 0 deletions html/elements/video.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@
},
"crossorigin": {
"__compat": {
"mdn_url": "https://developer.mozilla.org/docs/Web/HTML/Attributes/crossorigin",
"spec_url": "https://html.spec.whatwg.org/multipage/media.html#attr-media-crossorigin",
"tags": [
"web-features:video"
Expand Down
6 changes: 1 addition & 5 deletions lint/fixer/mdn-urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ const fixMDNURLs = (filename: string): void => {
continue;
}

const errors = processData(
feature.compat,
feature.path,
feature.path.split('.')[0],
);
const errors = processData(feature.compat, feature.path);

for (const error of errors) {
if (error.expected) {
Expand Down
Loading

0 comments on commit e6044d5

Please sign in to comment.