Skip to content

Support linting the spec #193

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

Merged
merged 3 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
"description": "The Source Map specification",
"scripts": {
"prebuild-only": "npm run clean && mkdir out && cp -R img out",
"build-only": "ecmarkup --verbose --load-biblio @tc39/ecma262-biblio spec.emu out/index.html",
"build": "npm run build-only",
"build-only": "npm run ecmarkup -- --verbose --load-biblio @tc39/ecma262-biblio spec.emu out/index.html",
"build-loose": "npm run build-only",
"build": "npm run build-only -- --lint-spec",
"clean": "rm -rf out",
"ecmarkup": "node ./scripts/ecmarkup.js",
"format": "emu-format --write spec.emu",
"test": "exit 0",
"watch": "npm run build-only -- --watch"
Expand Down
53 changes: 53 additions & 0 deletions scripts/ecmarkup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
function wrapWarnFunction(originalWarn) {
return (err) => {
if (
err.message.includes("Completion Record") ||
err.message.includes("an abrupt completion")
) {
// Ignore errors about completion records
return;
}

let match;
if (match = /^could not find definition for (\w+)$/.exec(err.message)) {
switch (match[1]) {
// This is correctly <dfn>ed as a reference from an external
// specification. However, ecmarkup only allows "calling" AOs and not
// <dfn>ed terms.
case "module_decode":
// Ecmarkup mistakenly detects HTTP in "an HTTP(S) scheme" as an AO
// call.
case "HTTP":
return;
}
}

originalWarn(err);
};
}

Object.defineProperty(Object.prototype, "warn", {
enumerable: false,
configurable: true,
get: () => undefined,
set(value) {
// Trying to detect this object:
// https://github.com/tc39/ecmarkup/blob/734baa009be2bdbab29c14a9e52ed3da1e26caa3/src/cli.ts#L104
if (
Object.hasOwn(this, "multipage") &&
Object.hasOwn(this, "outfile") &&
Object.hasOwn(this, "extraBiblios") &&
Object.hasOwn(this, "lintSpec")
) {
value = wrapWarnFunction(value);
}
Object.defineProperty(this, "warn", {
enumerable: true,
configurable: true,
writable: true,
value,
});
},
});

require("ecmarkup/bin/ecmarkup.js");
Loading