Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate spec_urls based on webref ids #23958

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions lint/linter/test-spec-urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* See LICENSE file for more information. */

import chalk from 'chalk-template';
import specData from 'web-specs' assert { type: 'json' };

import { Linter, Logger, LinterData } from '../utils.js';
import { CompatStatement } from '../../types/types.js';
Expand Down Expand Up @@ -41,19 +40,37 @@ const specsExceptions = [
'https://github.com/WebAssembly/multi-memory/blob/main/proposals',
];

const allowedSpecURLs = [
...(specData
.filter((spec) => spec.standing == 'good')
.map((spec) => [
spec.url,
spec.nightly?.url,
...(spec.nightly ? spec.nightly.alternateUrls : []),
spec.series.nightlyUrl,
])
.flat()
.filter((url) => !!url) as string[]),
...specsExceptions,
];
/**
* Get valid specification URLs from webref ids
* @returns array of valid spec urls (including fragment id)
*/
const getValidSpecURLs = async (): Promise<string[]> => {
const indexFile = await fetch(
'https://raw.githubusercontent.com/w3c/webref/main/ed/index.json',
);
const index = JSON.parse(await indexFile.text());

const ids: string[] = [];
index.results.forEach((result) => {
if (result.ids) {
ids.push(result.ids);
}
});

const specIDs: string[] = [];
await Promise.all(
ids.map(async (id) => {
const idFile = await fetch(
`https://raw.githubusercontent.com/w3c/webref/main/ed/${id}`,
);
const idResponse = JSON.parse(await idFile.text());
specIDs.push(...idResponse.ids);
Elchi3 marked this conversation as resolved.
Show resolved Hide resolved
}),
);
return specIDs;
};

const validSpecURLs = await getValidSpecURLs();

/**
* Process the data for spec URL errors
Expand All @@ -70,7 +87,10 @@ const processData = (data: CompatStatement, logger: Logger): void => {
: [data.spec_url];

for (const specURL of featureSpecURLs) {
if (!allowedSpecURLs.some((prefix) => specURL.startsWith(prefix))) {
if (
!validSpecURLs.includes(specURL) &&
!specsExceptions.some((host) => specURL.startsWith(host))
) {
logger.error(
chalk`Invalid specification URL found: {bold ${specURL}}. Check if:
- there is a more current specification URL
Expand Down
Loading