-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathspecs.ts
194 lines (180 loc) · 8.07 KB
/
specs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import assert from "node:assert/strict";
import webSpecs from 'web-specs' assert { type: 'json' };
import { features } from '../index.js';
// Specs needs to be in "good standing". Nightly URLs are used if available,
// otherwise the snapshot/versioned URL is used. See browser-specs/web-specs
// docs for more details:
// https://github.com/w3c/browser-specs/blob/main/README.md#standing
// https://github.com/w3c/browser-specs/blob/main/README.md#nightly
// https://github.com/w3c/browser-specs/blob/main/README.md#url
const specUrls: URL[] = webSpecs
.filter((spec) => spec.standing === 'good')
.flatMap(spec => {
return [
new URL(spec.nightly?.url ?? spec.url),
...(spec.nightly?.pages ?? []).map(page => new URL(page))
]
});
type allowlistItem = [url: string, message: string];
const defaultAllowlist: allowlistItem[] = [
// [
// "https://example.com/spec/",
// "Allowed because…. Remove this exception when https://example.com/org/repo/pull/1234 merges."
// ]
[
"https://wicg.github.io/controls-list/",
"Allowed because it's shipped in Chrome. Remove this exception if https://github.com/whatwg/html/pull/6715 is merged."
],
[
"https://www.w3.org/TR/webnn/",
"Allowed because this URL actually serves the same content as the Editor Draft URL, and because the ED URL is a bit verbose. See https://github.com/mdn/browser-compat-data/pull/22569#issuecomment-1992632118."
],
[
"https://github.com/WebAssembly/spec/blob/main/proposals/bulk-memory-operations/Overview.md",
"Allowed because there is no other specification to link to."
],
[
"https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md",
"Allowed because there is no other specification to link to."
],
[
"https://github.com/WebAssembly/extended-const/blob/main/proposals/extended-const/Overview.md",
"Allowed because there is no other specification to link to."
],
[
"https://github.com/WebAssembly/multi-memory/blob/main/proposals/multi-memory/Overview.md",
"Allowed because there is no other specification to link to."
],
[
"https://github.com/WebAssembly/spec/blob/main/proposals/multi-value/Overview.md",
"Allowed because there is no other specification to link to."
],
[
"https://github.com/WebAssembly/spec/blob/main/proposals/nontrapping-float-to-int-conversion/Overview.md",
"Allowed because there is no other specification to link to."
],
[
"https://github.com/WebAssembly/spec/blob/main/proposals/reference-types/Overview.md",
"Allowed because there is no other specification to link to."
],
[
"https://github.com/WebAssembly/spec/blob/main/proposals/sign-extension-ops/Overview.md",
"Allowed because there is no other specification to link to."
],
[
"https://github.com/WebAssembly/relaxed-simd/blob/main/proposals/relaxed-simd/Overview.md",
"Allowed because there is no other specification to link to."
],
[
"https://github.com/WebAssembly/tail-call/blob/main/proposals/tail-call/Overview.md",
"Allowed because there is no other specification to link to."
],
[
"https://github.com/WebAssembly/threads/blob/main/proposals/threads/Overview.md",
"Allowed because there is no other specification to link to."
],
[
"https://github.com/WebAssembly/function-references/blob/main/proposals/function-references/Overview.md",
"Allowed because there is no other specification to link to."
],
[
"https://github.com/WebAssembly/js-string-builtins/blob/main/proposals/js-string-builtins/Overview.md",
"Allowed because there is no other specification to link to."
],
[
"https://github.com/WebAssembly/memory64/blob/main/proposals/memory64/Overview.md",
"Allowed because there is no other specification to link to."
],
[
"https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/legacy/Exceptions.md",
"Allowed because there is no other specification to link to."
],
[
"https://immersive-web.github.io/webvr/spec/1.1/",
"Allowed because this is the legacy spec that defines WebVR."
],
[
"https://github.com/tc39/proposal-import-attributes/tree/abca60286360b47f9a6be25a28f489c2cb157beb",
"Allowed because import assertions were replaced in-place by import attributes. Remove this exception when javascript.statements.import.import_assertions is dropped from BCD in June 2026."
],
[
"https://open-ui.org/components/customizableselect/",
"Allowed because customizable select doesn't have a spec URL yet. And even when it does, it will be defined in multiple HTML, CSS, and ARIA specs. This OpenUI explainer is the only central place that currently defines the component. Remove this exception when customizable select has one or more spec URLs. See: #10557, #10586, #10629, #10633, and #10670 at github.com/whatwg/html/, #10691, #10865, #10936, and #10986 at github.com/w3c/csswg-drafts/, #2369, #2344, and #2360 at github.com/w3c/aria/, and #528 at github.com/w3c/html-aria"
],
[
"https://www.w3.org/TR/DOM-Level-2-Style/",
"Allowed because the css-object-model-discouraged feature points to it."
]
];
function isOK(url: URL, allowlist: allowlistItem[] = defaultAllowlist) {
for (const specUrl of specUrls) {
if (specUrl.origin === url.origin && specUrl.pathname === url.pathname) {
// that is, specUrl and url are the same, with the exception of the hash or query (`search`) string
return true;
}
}
for (const [specUrl, message] of allowlist) {
if (specUrl === url.toString()) {
console.warn(`${specUrl}: ${message}`);
return true;
}
}
return false;
}
function testIsOK() {
assert.ok(isOK(new URL("https://tc39.es/ecma262/multipage/")));
assert.ok(isOK(new URL("https://tc39.es/ecma262/multipage/indexed-collections.html#sec-array.prototype.at")));
assert.ok(!isOK(new URL("https://typo.csswg.org/css-anchor-position-1/#anchoring")));
assert.ok(!isOK(new URL("https://w3c.github.io/gamepad/extensions.htmltypo")))
// Skip noisy test
// assert.ok(isOK(new URL("https://www.example.com/"), [["https://www.example.com/", "Remove this exception when…"]]));
};
testIsOK();
/**
* Print an array of potential spec URLs.
*/
function suggestSpecs(bad: URL): void {
const searchBy = bad.pathname.replaceAll("/", "");
const suggestions = specUrls.filter((specUrl) => specUrl.toString().includes(searchBy)).map(u => `- ${u}`);
if (suggestions.length > 0) {
console.warn("Did you mean one of these?");
console.warn(`${suggestions.join('\n')}`);
console.warn();
}
}
let checkedFeatures = 0;
let checkedSpecs = 0;
let errors = 0;
// Ensure every exception in defaultAllowlist is needed
for (const [allowedUrl, message] of defaultAllowlist) {
if (isOK(new URL(allowedUrl), [])) {
console.error(`${allowedUrl}: ${message}`);
console.error(`${allowedUrl} is now known to web-specs.`);
errors++;
}
}
for (const [id, data] of Object.entries(features)) {
const specs = Array.isArray(data.spec) ? data.spec : [data.spec];
for (const spec of specs) {
let url: URL;
try {
url = new URL(spec);
} catch (error) {
console.error(`Invalid URL "${spec}" found in spec for "${data.name}"`);
errors++;
}
if (url && !isOK(url)) {
console.error(`URL for ${id} not in web-specs: ${url.toString()}`);
suggestSpecs(url);
errors++;
}
checkedSpecs++;
}
checkedFeatures++;
}
if (errors) {
console.log(`\nChecked ${checkedSpecs} specs in ${checkedFeatures} features, found ${errors} error(s)`);
process.exit(1);
} else {
console.log(`\nChecked ${checkedSpecs} specs in ${checkedFeatures} features, no errors`);
}