Skip to content

Commit

Permalink
Fix false positives
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Oct 1, 2024
1 parent cddf15d commit b9b9f14
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 8 deletions.
1 change: 1 addition & 0 deletions config/allowed-code-link-text.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ contain-intrinsic-size: auto none
cubic-bezier(0, 0, 1, 1)
cubic-bezier(p1, p2, p3, p4)
delete obj.x
for each...in
import ... with { type: "css" }
instanceof Array
minmax(auto, max-content)
Expand Down
78 changes: 78 additions & 0 deletions config/no-bcd.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
This file contains BCD keys that can be derived from content pages,
but are not actually tracked in BCD usually because support is not interesting
or browser support is irrelevant.
Use two-space indent for comments.

html.global_attributes.itemid
html.global_attributes.itemprop
html.global_attributes.itemref
html.global_attributes.itemscope
html.global_attributes.itemtype

http.headers.Accept-Charset
http.headers.Accept-Patch
http.headers.Accept-Post

https://github.com/mdn/browser-compat-data/pull/23529
http.status.100
http.status.101
http.status.102
http.status.200
http.status.201
http.status.202
http.status.203
http.status.204
http.status.205
http.status.206
http.status.207
http.status.208
http.status.226
http.status.300
http.status.301
http.status.302
http.status.303
http.status.304
http.status.307
http.status.400
http.status.401
http.status.402
http.status.403
http.status.404
http.status.405
http.status.406
http.status.407
http.status.408
http.status.409
http.status.410
http.status.411
http.status.412
http.status.413
http.status.414
http.status.415
http.status.416
http.status.417
http.status.418
http.status.421
http.status.422
http.status.423
http.status.424
http.status.426
http.status.428
http.status.429
http.status.431
http.status.451
http.status.500
http.status.501
http.status.502
http.status.503
http.status.504
http.status.505
http.status.506
http.status.507
http.status.508
http.status.510
http.status.511

https://github.com/mdn/browser-compat-data/pull/23774
html.manifest.categories
html.manifest.screenshots
49 changes: 42 additions & 7 deletions src/server/check-bcd-matching.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import nodes from "../../data/nodes.json" with { type: "json" };
import bcdData from "@mdn/browser-compat-data" with { type: "json" };
import { readConfig, configHas } from "./config.js";
import { getBCD } from "./utils.js";
import { getBCD, readConfig } from "./utils.js";

const dictionaries = new Map(
(await readConfig("dictionaries.txt")).map((x) => [x, false]),
);

const noBCD = new Map((await readConfig("no-bcd.txt")).map((x) => [x, false]));

function htmlAttrToBCD(attrName: string, elemName: string) {
if (attrName === "data-*") {
attrName = "data_attributes";
Expand Down Expand Up @@ -166,7 +168,14 @@ function expectedBCD(node: any): "Unexpected page type" | "ignore" | string[] {
return [`html.elements.${elemName}`];
}
// Mozilla/Add-ons/WebExtensions/
case "webextension-api-function":
case "webextension-api-function": {
const match = node.id.match(
/^\/en-US\/docs\/Mozilla\/Add-ons\/WebExtensions\/Content_scripts\/([^/]+)$/,
);
if (match) {
return [`webextensions.content_scripts.${match[1]}`];
}
}
case "webextension-api-event":
case "webextension-api-property":
case "webextension-api-type": {
Expand Down Expand Up @@ -221,11 +230,33 @@ function expectedBCD(node: any): "Unexpected page type" | "ignore" | string[] {
case "webgl-extension-method": {
const match = node.id.match(/^\/en-US\/docs\/Web\/API\/(.+)$/);
if (!match) return "Unexpected page type";
const path = dictionaryToBCD(
match[1]
.replaceAll("/", ".")
.replace(/^CSS\.factory_functions_static$/, "CSS"),
);
switch (match[1]) {
case "CSS/factory_functions_static":
return [`api.CSS`];
// These pages coalesce multiple methods into one, and only display one BCD
case "WebGL2RenderingContext/clearBuffer":
return [`api.WebGL2RenderingContext.clearBufferiv`];
case "WebGL2RenderingContext/samplerParameter":
return [`api.WebGL2RenderingContext.samplerParameteri`];
case "WebGL2RenderingContext/uniform":
return [`api.WebGL2RenderingContext.uniform1ui`];
case "WebGL2RenderingContext/uniformMatrix":
return [`api.WebGL2RenderingContext.uniformMatrix2fv`];
case "WebGL2RenderingContext/vertexAttribI":
return [`api.WebGL2RenderingContext.vertexAttribI4i`];
case "WebGLRenderingContext/texParameter":
return [
`api.WebGLRenderingContext.texParameterf`,
`api.WebGLRenderingContext.texParameteri`,
];
case "WebGLRenderingContext/uniform":
return [`api.WebGLRenderingContext.uniform1f`];
case "WebGLRenderingContext/uniformMatrix":
return [`api.WebGLRenderingContext.uniformMatrix2fv`];
case "WebGLRenderingContext/vertexAttrib":
return [`api.WebGLRenderingContext.vertexAttrib1f`];
}
const path = dictionaryToBCD(match[1].replaceAll("/", "."));
if (configHas(dictionaries, path.split(".")[0])) return [];
return [`api.${path}`];
}
Expand Down Expand Up @@ -521,6 +552,7 @@ export function checkBCDMatching(
}
const expectedExisting = expected.filter((x) => getBCD(bcdData, x));
if (!expectedExisting.length && expected.length) {
if (configHas(noBCD, node.id)) continue;
report(node, "Not in BCD", expected.join("\n"));
continue;
}
Expand All @@ -542,4 +574,7 @@ export function postCheckBCDMatching() {
for (const [name, used] of dictionaries) {
if (!used) console.warn(name, "is no longer documented");
}
for (const [name, used] of noBCD) {
if (!used) console.warn(name, "is no longer documented");
}
}
2 changes: 1 addition & 1 deletion src/server/create-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ for (const node of nodes) {
pageToSidebarId.set(node.id, processedSidebars.get(normalizedHTML)!.id);
continue;
}
const $ = load(sidebarHTML);
const $ = load(normalizedHTML);
const links = $("a")
.map((i, a) => ({
href: $(a).attr("href")?.replace(/\/$/, ""),
Expand Down

0 comments on commit b9b9f14

Please sign in to comment.