-
Notifications
You must be signed in to change notification settings - Fork 17
/
.spec-urls-check.js
executable file
·470 lines (455 loc) · 19.5 KB
/
.spec-urls-check.js
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
#!/usr/bin/env node
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
import chalk from "chalk";
import { readFileSync, existsSync, statSync, readdirSync } from "fs";
import request from "sync-request";
import { resolve, extname, join, basename } from "path";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
import { JSDOM } from "jsdom";
const log = (msg) => console.log(`${msg}`);
const info = (msg) => console.log(chalk`{keyword('dimgrey') ${msg}}`);
const warn = (msg) => console.warn(chalk`{yellowBright ${msg}}`);
const error = (msg) => console.error(chalk`{redBright ${msg}}`);
const needsSpecURL = (mdnURL) => {
const exceptions = [
"https://developer.mozilla.org/docs/Web/API/CanvasRenderingContext2D/createConicGradient",
"https://developer.mozilla.org/docs/Web/API/Document/featurePolicy",
"https://developer.mozilla.org/docs/Web/API/FeaturePolicy/allowedFeatures",
"https://developer.mozilla.org/docs/Web/API/FeaturePolicy/allowsFeature",
"https://developer.mozilla.org/docs/Web/API/FeaturePolicy/features",
"https://developer.mozilla.org/docs/Web/API/FeaturePolicy/getAllowlistForFeature",
"https://developer.mozilla.org/docs/Web/API/FeaturePolicy",
"https://developer.mozilla.org/docs/Web/API/GlobalEventHandlers/onloadend",
"https://developer.mozilla.org/docs/Web/API/HTMLElement/inert",
"https://developer.mozilla.org/docs/Web/API/HTMLIFrameElement/featurePolicy",
"https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/controller",
"https://developer.mozilla.org/docs/Web/API/HTMLMediaElement/mediaGroup",
"https://developer.mozilla.org/docs/Web/API/MouseEvent/region",
// In the spec, this one is defined by reference to the WebIDL spec
"https://developer.mozilla.org/docs/Web/API/PaymentResponse/toJSON",
// iterables; we explicitly don’t want spec URLs for these
"https://developer.mozilla.org/docs/Web/API/CSSTransformValue/entries",
"https://developer.mozilla.org/docs/Web/API/CSSTransformValue/forEach",
"https://developer.mozilla.org/docs/Web/API/CSSTransformValue/keys",
"https://developer.mozilla.org/docs/Web/API/CSSTransformValue/values",
"https://developer.mozilla.org/docs/Web/API/CSSUnparsedValue/entries",
"https://developer.mozilla.org/docs/Web/API/CSSUnparsedValue/forEach",
"https://developer.mozilla.org/docs/Web/API/CSSUnparsedValue/keys",
"https://developer.mozilla.org/docs/Web/API/CSSUnparsedValue/values",
"https://developer.mozilla.org/docs/Web/API/DOMTokenList/entries",
"https://developer.mozilla.org/docs/Web/API/DOMTokenList/forEach",
"https://developer.mozilla.org/docs/Web/API/DOMTokenList/keys",
"https://developer.mozilla.org/docs/Web/API/DOMTokenList/values",
"https://developer.mozilla.org/docs/Web/API/FontFaceSet/entries",
"https://developer.mozilla.org/docs/Web/API/FormData/entries",
"https://developer.mozilla.org/docs/Web/API/FormData/keys",
"https://developer.mozilla.org/docs/Web/API/FormData/values",
"https://developer.mozilla.org/docs/Web/API/Headers/entries",
"https://developer.mozilla.org/docs/Web/API/Headers/keys",
"https://developer.mozilla.org/docs/Web/API/Headers/values",
"https://developer.mozilla.org/docs/Web/API/HTMLInputElement/checkValidity",
"https://developer.mozilla.org/docs/Web/API/HTMLInputElement/setCustomValidity",
"https://developer.mozilla.org/docs/Web/API/KeyboardLayoutMap/entries",
"https://developer.mozilla.org/docs/Web/API/KeyboardLayoutMap/forEach",
"https://developer.mozilla.org/docs/Web/API/KeyboardLayoutMap/get",
"https://developer.mozilla.org/docs/Web/API/KeyboardLayoutMap/has",
"https://developer.mozilla.org/docs/Web/API/KeyboardLayoutMap/keys",
"https://developer.mozilla.org/docs/Web/API/KeyboardLayoutMap/size",
"https://developer.mozilla.org/docs/Web/API/KeyboardLayoutMap/values",
"https://developer.mozilla.org/docs/Web/API/MediaKeyStatusMap/entries",
"https://developer.mozilla.org/docs/Web/API/MediaKeyStatusMap/forEach",
"https://developer.mozilla.org/docs/Web/API/MediaKeyStatusMap/keys",
"https://developer.mozilla.org/docs/Web/API/MediaKeyStatusMap/values",
"https://developer.mozilla.org/docs/Web/API/NodeList/entries",
"https://developer.mozilla.org/docs/Web/API/NodeList/forEach",
"https://developer.mozilla.org/docs/Web/API/NodeList/keys",
"https://developer.mozilla.org/docs/Web/API/NodeList/values",
"https://developer.mozilla.org/docs/Web/API/StylePropertyMapReadOnly/entries",
"https://developer.mozilla.org/docs/Web/API/StylePropertyMapReadOnly/forEach",
"https://developer.mozilla.org/docs/Web/API/StylePropertyMapReadOnly/keys",
"https://developer.mozilla.org/docs/Web/API/StylePropertyMapReadOnly/values",
"https://developer.mozilla.org/docs/Web/API/URLSearchParams/entries",
"https://developer.mozilla.org/docs/Web/API/URLSearchParams/forEach",
"https://developer.mozilla.org/docs/Web/API/URLSearchParams/keys",
"https://developer.mozilla.org/docs/Web/API/URLSearchParams/values",
"https://developer.mozilla.org/docs/Web/API/XRInputSourceArray/entries",
"https://developer.mozilla.org/docs/Web/API/XRInputSourceArray/forEach",
"https://developer.mozilla.org/docs/Web/API/XRInputSourceArray/keys",
"https://developer.mozilla.org/docs/Web/API/XRInputSourceArray/values",
"https://developer.mozilla.org/docs/Web/API/CSSTransformValue/entries",
"https://developer.mozilla.org/docs/Web/API/CSSTransformValue/forEach",
"https://developer.mozilla.org/docs/Web/API/CSSTransformValue/keys",
"https://developer.mozilla.org/docs/Web/API/CSSTransformValue/values",
"https://developer.mozilla.org/docs/Web/API/CSSUnparsedValue/entries",
"https://developer.mozilla.org/docs/Web/API/CSSUnparsedValue/forEach",
"https://developer.mozilla.org/docs/Web/API/CSSUnparsedValue/keys",
"https://developer.mozilla.org/docs/Web/API/CSSUnparsedValue/values",
"https://developer.mozilla.org/docs/Web/API/DOMTokenList/entries",
"https://developer.mozilla.org/docs/Web/API/DOMTokenList/forEach",
"https://developer.mozilla.org/docs/Web/API/DOMTokenList/keys",
"https://developer.mozilla.org/docs/Web/API/DOMTokenList/values",
"https://developer.mozilla.org/docs/Web/API/FormData/entries",
"https://developer.mozilla.org/docs/Web/API/FormData/keys",
"https://developer.mozilla.org/docs/Web/API/FormData/values",
"https://developer.mozilla.org/docs/Web/API/Headers/entries",
"https://developer.mozilla.org/docs/Web/API/Headers/keys",
"https://developer.mozilla.org/docs/Web/API/Headers/values",
"https://developer.mozilla.org/docs/Web/API/KeyboardLayoutMap/entries",
"https://developer.mozilla.org/docs/Web/API/KeyboardLayoutMap/forEach",
"https://developer.mozilla.org/docs/Web/API/KeyboardLayoutMap/get",
"https://developer.mozilla.org/docs/Web/API/KeyboardLayoutMap/has",
"https://developer.mozilla.org/docs/Web/API/KeyboardLayoutMap/keys",
"https://developer.mozilla.org/docs/Web/API/KeyboardLayoutMap/size",
"https://developer.mozilla.org/docs/Web/API/KeyboardLayoutMap/values",
"https://developer.mozilla.org/docs/Web/API/MediaKeyStatusMap/entries",
"https://developer.mozilla.org/docs/Web/API/MediaKeyStatusMap/forEach",
"https://developer.mozilla.org/docs/Web/API/MediaKeyStatusMap/keys",
"https://developer.mozilla.org/docs/Web/API/MediaKeyStatusMap/values",
"https://developer.mozilla.org/docs/Web/API/NodeList/entries",
"https://developer.mozilla.org/docs/Web/API/NodeList/forEach",
"https://developer.mozilla.org/docs/Web/API/NodeList/keys",
"https://developer.mozilla.org/docs/Web/API/NodeList/values",
"https://developer.mozilla.org/docs/Web/API/StylePropertyMapReadOnly/entries",
"https://developer.mozilla.org/docs/Web/API/StylePropertyMapReadOnly/forEach",
"https://developer.mozilla.org/docs/Web/API/StylePropertyMapReadOnly/keys",
"https://developer.mozilla.org/docs/Web/API/StylePropertyMapReadOnly/values",
"https://developer.mozilla.org/docs/Web/API/URLSearchParams/entries",
"https://developer.mozilla.org/docs/Web/API/URLSearchParams/forEach",
"https://developer.mozilla.org/docs/Web/API/URLSearchParams/keys",
"https://developer.mozilla.org/docs/Web/API/URLSearchParams/values",
"https://developer.mozilla.org/docs/Web/API/XRInputSourceArray/entries",
"https://developer.mozilla.org/docs/Web/API/XRInputSourceArray/forEach",
"https://developer.mozilla.org/docs/Web/API/XRInputSourceArray/keys",
"https://developer.mozilla.org/docs/Web/API/XRInputSourceArray/values",
"https://developer.mozilla.org/docs/Web/MathML/Element/menclose",
"https://developer.mozilla.org/docs/Web/MathML/Global_attributes/href",
// FIXME: for this one we really do need a spec URL
"https://developer.mozilla.org/docs/Web/API/GamepadButton/touched",
// FIXME: for this one we really do need a spec URL
"https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite",
// FIXME: for this one we really do need a spec URL
"https://developer.mozilla.org/docs/Web/API/XRSession/requestHitTestSource",
// FIXME: for all these we really do need spec URLs
"https://developer.mozilla.org/docs/Web/API/NDEFMessage/NDEFMessage",
"https://developer.mozilla.org/docs/Web/API/NDEFReadingEvent/NDEFReadingEvent",
"https://developer.mozilla.org/docs/Web/API/NDEFReadingEvent/message",
"https://developer.mozilla.org/docs/Web/API/NDEFReadingEvent/serialNumber",
// FIXME: for all these we really do need spec URLs
"https://developer.mozilla.org/docs/Web/API/FontFaceSet/forEach",
"https://developer.mozilla.org/docs/Web/API/FontFaceSet/has",
"https://developer.mozilla.org/docs/Web/API/FontFaceSet/keys",
"https://developer.mozilla.org/docs/Web/API/FontFaceSet/size",
"https://developer.mozilla.org/docs/Web/API/FontFaceSet/values",
// FIXME: for these we really do need spec URLs
"https://developer.mozilla.org/docs/Web/API/TextDecoder/fatal",
"https://developer.mozilla.org/docs/Web/API/TextDecoder/ignoreBOM",
// FIXME: for all these we really do need spec URLs
"https://developer.mozilla.org/docs/Web/API/TextTrack/activeCues",
"https://developer.mozilla.org/docs/Web/API/TextTrack/addCue",
"https://developer.mozilla.org/docs/Web/API/TextTrack/cues",
"https://developer.mozilla.org/docs/Web/API/TextTrack/id",
"https://developer.mozilla.org/docs/Web/API/TextTrack/inBandMetadataTrackDispatchType",
"https://developer.mozilla.org/docs/Web/API/TextTrack/kind",
"https://developer.mozilla.org/docs/Web/API/TextTrack/label",
"https://developer.mozilla.org/docs/Web/API/TextTrack/language",
"https://developer.mozilla.org/docs/Web/API/TextTrack/removeCue",
"https://developer.mozilla.org/docs/Web/API/TextTrackCue/endTime",
"https://developer.mozilla.org/docs/Web/API/TextTrackCue/id",
"https://developer.mozilla.org/docs/Web/API/TextTrackCue/pauseOnExit",
"https://developer.mozilla.org/docs/Web/API/TextTrackCue/startTime",
"https://developer.mozilla.org/docs/Web/API/TextTrackCue/track",
"https://developer.mozilla.org/docs/Web/API/VTTCue/align",
"https://developer.mozilla.org/docs/Web/API/VTTCue/getCueAsHTML",
"https://developer.mozilla.org/docs/Web/API/VTTCue/line",
"https://developer.mozilla.org/docs/Web/API/VTTCue/lineAlign",
"https://developer.mozilla.org/docs/Web/API/VTTCue/position",
"https://developer.mozilla.org/docs/Web/API/VTTCue/positionAlign",
"https://developer.mozilla.org/docs/Web/API/VTTCue/region",
"https://developer.mozilla.org/docs/Web/API/VTTCue/size",
"https://developer.mozilla.org/docs/Web/API/VTTCue/snapToLines",
"https://developer.mozilla.org/docs/Web/API/VTTCue/text",
"https://developer.mozilla.org/docs/Web/API/VTTCue/vertical",
// FIXME: dunno what the problem is with the following
"https://developer.mozilla.org/docs/Web/CSS/path()",
// ES spec has no one “spread syntax” anchor we can link to; multiple
// sections instead, in different parts of the spec, for subitems/
// subfeatures — specific spread types — we already have spec_url’s for
"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Spread_syntax",
];
if (exceptions.includes(mdnURL)) {
return false;
}
const slugSubstringsNotNeedingSpecURLs = [];
return !slugSubstringsNotNeedingSpecURLs.some((substring) =>
mdnURL.includes(substring)
);
};
log("loading SPECURLS.json...");
const SPECURLS = JSON.parse(readFileSync("SPECURLS.json", "utf-8"));
const MDNURLS = [];
let file;
chalk.level = 3;
const checkSpecURLs = (key, data) => {
let deprecated = false;
let standard = true;
if (data && data instanceof Object && "__compat" in data) {
const feature = key;
const bcdFeatureData = data.__compat;
const mdn_url = bcdFeatureData.mdn_url;
if ("standard_track" in bcdFeatureData.status) {
standard = bcdFeatureData.status.standard_track;
if (!standard) {
info(`${file}:${feature}: non-standard`);
}
}
if ("deprecated" in bcdFeatureData.status) {
deprecated = bcdFeatureData.status.deprecated;
if (!deprecated) {
info(`${file}:${feature}: deprecated`);
}
}
if (!mdn_url && !(deprecated || !standard)) {
if (!key.includes("_")) {
warn(`${file}:${feature}: no mdn_url`);
}
}
const spec_url = bcdFeatureData.spec_url;
if (spec_url && spec_url.length !== 0) {
if (deprecated) {
warn(`${file}:${feature}: deprecated but has spec_url`);
}
if (!standard) {
warn(`${file}:${feature}: nonstandard but has spec_url`);
}
if (spec_url instanceof Array) {
for (const url of spec_url) {
checkSpecURL(file, feature, url, mdn_url, standard, deprecated);
}
} else {
checkSpecURL(file, feature, spec_url, mdn_url, standard, deprecated);
}
} else if (mdn_url && !new URL(mdn_url).hash && standard && !deprecated) {
if (needsSpecURL(mdn_url) && MDNURLS.includes(mdn_url)) {
error(`${file}:${feature}: ${mdn_url} needs spec URL`);
}
}
}
return data;
};
const checkSpecURL = (
file,
feature,
spec_url,
mdn_url,
standard,
deprecated
) => {
// FIXME temporary
if (spec_url.startsWith("https://tc39.es/proposal-resizablearraybuffer")) {
return;
}
// FIXME temporary
if (
spec_url.startsWith(
"https://tc39.es/proposal-array-grouping/#sec-array.prototype.group"
)
) {
return;
}
// FIXME temporary
if (
spec_url.startsWith(
"https://tc39.es/proposal-array-grouping/#sec-array.prototype.grouptomap"
)
) {
return;
}
// FIXME temporary https://github.com/w3c/svgwg/pull/879
// PR merged but spec output not regenerated yet...
if (
spec_url.startsWith(
"https://svgwg.org/svg2-draft/styling.html#__svg__SVGStyleElement__disabled"
)
) {
return;
}
// Permanently ignore
if (
spec_url.startsWith(
"https://wicg.github.io/savedata/#save-data-request-header-field"
)
) {
return;
}
// Redirects from https://w3c.github.io/device-memory; ignore
if (spec_url.startsWith("https://www.w3.org/TR/device-memory/")) {
return;
}
if (spec_url.startsWith("https://www.w3.org/TR/SVG11/")) {
return;
}
if (spec_url.startsWith("https://www.w3.org/TR/WOFF/")) {
return;
}
// Permanently broken; redirects to https://www.w3.org/TR/device-memory/
if (spec_url.startsWith("https://w3c.github.io/device-memory/")) {
return;
}
if (
spec_url.startsWith(
"https://w3c.github.io/mst-content-hint/#dom-mediastreamtrack-contenthint"
)
) {
return; // undocumented in MDN
}
if (
spec_url.startsWith(
"https://w3c.github.io/web-share-target/#share_target-member"
)
) {
return; // undocumented in MDN
}
if (
spec_url.startsWith(
"https://wicg.github.io/permissions-request/#dom-permissions-request"
)
) {
return; // undocumented in MDN
}
if (spec_url.startsWith("https://tc39.es/proposal-temporal/")) {
return; // undocumented in MDN
}
if (spec_url.startsWith("https://w3c.github.io/mathml/#fund_globatt")) {
return; // not in MathML Core
}
// Ancient and unimplemented
if (spec_url.startsWith("https://w3c.github.io/setImmediate/")) {
return;
}
if (
spec_url.startsWith("https://www.rfc-editor.org/rfc/rfc2324") ||
spec_url.startsWith("https://www.rfc-editor.org/rfc/rfc7168")
) {
// "I'm a teapot" RFC; ignore
return;
}
if (spec_url.startsWith("https://httpwg.org/specs/rfc7725.html")) {
// HTTP status code 405; irrelevant
return;
}
if (spec_url.startsWith("https://httpwg.org/specs/rfc8470.html")) {
// HTTP Early-Data header; irrelevant
return;
}
if (
spec_url.startsWith(
"https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-expect-ct"
)
) {
// HTTP Expect-CT header; irrelevant
return;
}
if (
spec_url.startsWith(
"https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-digest-headers"
)
) {
// HTTP Digest header; irrelevant
return;
}
if (
spec_url.startsWith(
"https://datatracker.ietf.org/doc/html/draft-davidben-http-client-hint-reliability"
)
) {
// HTTP Critical-CH header; irrelevant
return;
}
if (
spec_url.match(/https:\/\/registry.khronos.org\/webgl\/extensions\/[^/]+\//)
) {
return;
}
if (SPECURLS.includes(spec_url)) {
return;
}
if (mdn_url && standard && !deprecated) {
error(`${file}:${feature}: bad spec URL ${spec_url} bad fragment?`);
}
};
/**
* @param {Promise<void>} filename
*/
const processFile = (filename) => {
log(`Processing ${filename}`);
JSON.parse(readFileSync(filename, "utf-8").trim(), checkSpecURLs);
};
if (process.argv[1] === fileURLToPath(import.meta.url)) {
/**
* @param {string[]} files
*/
const load = (...files) => {
const options = {
headers: { "User-Agent": "bcd-maintenance-script" },
gzip: true,
};
const response = request(
"GET",
"https://developer.mozilla.org/sitemaps/en-us/sitemap.xml.gz",
options
);
const xml = response.getBody();
const dom = new JSDOM("");
const DOMParser = dom.window.DOMParser;
const parser = new DOMParser();
const doc = parser.parseFromString(xml, "text/xml");
const loc_elements = doc.documentElement.querySelectorAll("loc");
for (let i = 0; i < loc_elements.length; i++) {
const path = loc_elements[i].textContent.substring(36);
MDNURLS.push("https://developer.mozilla.org/" + path);
}
for (file of files) {
if (file.indexOf(__dirname) !== 0) {
file = resolve(__dirname, file);
}
if (!existsSync(file)) {
continue; // Ignore non-existent files
}
if (statSync(file).isFile()) {
if (extname(file) === ".json") {
processFile(file);
}
continue;
}
load(...subFiles(file));
}
};
const subFiles = (file) =>
readdirSync(file).map((subfile) => {
return join(file, subfile);
});
let subdir = "";
if (basename(process.env.PWD) !== "browser-compat-data") {
subdir = "browser-compat-data/";
}
if (process.argv[2] && process.argv[2] !== "all") {
load(subdir + process.argv[2]);
} else {
load(
subdir + "api",
subdir + "css",
subdir + "html",
subdir + "http",
subdir + "javascript",
subdir + "mathml",
subdir + "svg",
subdir + "webdriver"
);
}
}
export default { checkSpecURLs, processFile };