mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 10:59:13 +00:00
chore(lint): add .out file reference checker (#27078)
Co-authored-by: David Sherret <dsherret@gmail.com>
This commit is contained in:
parent
4700f12ddc
commit
42b71d82db
765 changed files with 517 additions and 4766 deletions
|
@ -3,7 +3,16 @@
|
|||
|
||||
// deno-lint-ignore-file no-console
|
||||
|
||||
import { buildMode, getPrebuilt, getSources, join, ROOT_PATH } from "./util.js";
|
||||
import {
|
||||
buildMode,
|
||||
dirname,
|
||||
getPrebuilt,
|
||||
getSources,
|
||||
join,
|
||||
parseJSONC,
|
||||
ROOT_PATH,
|
||||
walk,
|
||||
} from "./util.js";
|
||||
import { checkCopyright } from "./copyright_checker.js";
|
||||
import * as ciFile from "../.github/workflows/ci.generate.ts";
|
||||
|
||||
|
@ -25,6 +34,7 @@ if (js) {
|
|||
promises.push(dlintPreferPrimordials());
|
||||
promises.push(ensureCiYmlUpToDate());
|
||||
promises.push(ensureNoNewITests());
|
||||
promises.push(ensureNoUnusedOutFiles());
|
||||
|
||||
if (rs) {
|
||||
promises.push(checkCopyright());
|
||||
|
@ -251,3 +261,49 @@ async function ensureNoNewITests() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function ensureNoUnusedOutFiles() {
|
||||
const specsDir = join(ROOT_PATH, "tests", "specs");
|
||||
const outFilePaths = new Set(
|
||||
(await Array.fromAsync(
|
||||
walk(specsDir, { exts: [".out"] }),
|
||||
)).map((entry) => entry.path),
|
||||
);
|
||||
const testFiles = (await Array.fromAsync(
|
||||
walk(specsDir, { exts: [".jsonc"] }),
|
||||
)).filter((entry) => {
|
||||
return entry.path.endsWith("__test__.jsonc");
|
||||
});
|
||||
|
||||
function checkObject(baseDirPath, obj) {
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
if (typeof value === "object") {
|
||||
checkObject(baseDirPath, value);
|
||||
} else if (key === "output" && typeof value === "string") {
|
||||
const outFilePath = join(baseDirPath, value);
|
||||
outFilePaths.delete(outFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const testFile of testFiles) {
|
||||
try {
|
||||
const text = await Deno.readTextFile(testFile.path);
|
||||
const data = parseJSONC(text);
|
||||
checkObject(dirname(testFile.path), data);
|
||||
} catch (err) {
|
||||
throw new Error("Failed reading: " + testFile.path, {
|
||||
cause: err,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const notFoundPaths = Array.from(outFilePaths);
|
||||
if (notFoundPaths.length > 0) {
|
||||
notFoundPaths.sort(); // be deterministic
|
||||
for (const file of notFoundPaths) {
|
||||
console.error(`Unreferenced .out file: ${file}`);
|
||||
}
|
||||
throw new Error(`${notFoundPaths.length} unreferenced .out files`);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue