Skip to content

Commit

Permalink
Convert spec URLs test to linter unit (mdn#16522)
Browse files Browse the repository at this point in the history
Co-authored-by: Philip Jägenstedt <philip@foolip.org>
  • Loading branch information
2 people authored and pull[bot] committed Sep 11, 2023
1 parent 8b871ac commit d51c971
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 78 deletions.
2 changes: 2 additions & 0 deletions test/linter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import testLinks from './test-links.js';
import testNotes from './test-notes.js';
import testPrefix from './test-prefix.js';
import testSchema from './test-schema.js';
import testSpecURLs from './test-spec-urls.js';
import testStatus from './test-status.js';
import testStyle from './test-style.js';
import testVersions from './test-versions.js';
Expand All @@ -24,6 +25,7 @@ export default new Linters([
testNotes,
testPrefix,
testSchema,
testSpecURLs,
testStatus,
testStyle,
testVersions,
Expand Down
91 changes: 91 additions & 0 deletions test/linter/test-spec-urls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* This file is a part of @mdn/browser-compat-data
* See LICENSE file for more information. */

import chalk from 'chalk-template';

import specData from 'browser-specs' assert { type: 'json' };

/*
* Before adding an exception, open an issue with https://github.com/w3c/browser-specs to
* see if a spec should be added there instead.
* When adding an exception here, provide a reason and indicate how the exception can be removed.
*/
const specsExceptions = [
// Remove once https://github.com/whatwg/html/pull/6715 is resolved
'https://wicg.github.io/controls-list/',

// Remove once Window.{clearImmediate,setImmediate} are irrelevant and removed
'https://w3c.github.io/setImmediate/',

// Remove if supported in browser-specs https://github.com/w3c/browser-specs/issues/339
'https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-digest-headers-05',
'https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-expect-ct-08',

// Exception for April Fools' joke for "418 I'm a teapot"
'https://www.rfc-editor.org/rfc/rfc2324',

// Unfortunately this doesn't produce a rendered spec, so it isn't in browser-specs
// Remove if it is in the main ECMA spec
'https://github.com/tc39/proposal-regexp-legacy-features/',

// For the 'shared' flag in WebAssembly.Memory
// Remove if this spec will be merged with the main WebAssembly spec
'https://webassembly.github.io/threads/js-api/',

// Not really a browser feature, thus not in browser-specs
// Remove if it is in the main ECMA spec
'https://tc39.es/proposal-hashbang/out.html',

// Remove if https://github.com/w3c/webrtc-extensions/issues/108 is closed
'https://w3c.github.io/webrtc-extensions/',

// Remove if https://github.com/w3c/mathml/issues/216 is resolved
'https://w3c.github.io/mathml/',
];

const allowedSpecURLs = [
...specData.map((spec) => spec.url),
...specData.map((spec) => spec.nightly.url),
...specData.map((spec) => spec.series.nightlyUrl),
...specsExceptions,
];

/**
* @typedef {import('../../types').Identifier} Identifier
* @typedef {import('../utils').Logger} Logger
*/

/**
* Process the data for spec URL errors
*
* @param {Identifier} data The data to test
* @param {Logger} logger The logger to output errors to
* @returns {void}
*/
function processData(data, logger) {
if (!data.spec_url) {
return;
}

const featureSpecURLs = Array.isArray(data.spec_url)
? data.spec_url
: [data.spec_url];

for (const specURL of featureSpecURLs) {
if (!allowedSpecURLs.some((prefix) => specURL.startsWith(prefix))) {
logger.error(
chalk`Invalid specification URL found: {bold ${specURL}}. Try a more current specification URL and/or check if the specification URL is listed in https://github.com/w3c/browser-specs.`,
);
}
}
}

export default {
name: 'Spec URLs',
description:
'Ensure the spec_url values match spec URLs in w3c/browser-specs (or defined exceptions)',
scope: 'feature',
check(logger, { data }) {
processData(data, logger);
},
};
78 changes: 0 additions & 78 deletions test/spec-urls.test.js

This file was deleted.

0 comments on commit d51c971

Please sign in to comment.