2020-11-05 09:53:21 -05:00
|
|
|
#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run
|
2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2020-11-05 09:53:21 -05:00
|
|
|
import {
|
|
|
|
buildMode,
|
|
|
|
getPrebuiltToolPath,
|
|
|
|
getSources,
|
2021-01-16 18:32:59 -05:00
|
|
|
join,
|
2020-11-05 09:53:21 -05:00
|
|
|
ROOT_PATH,
|
|
|
|
} from "./util.js";
|
|
|
|
|
|
|
|
async function dlint() {
|
2021-01-16 18:32:59 -05:00
|
|
|
const configFile = join(ROOT_PATH, ".dlint.json");
|
2020-11-05 09:53:21 -05:00
|
|
|
const execPath = getPrebuiltToolPath("dlint");
|
|
|
|
console.log("dlint");
|
|
|
|
|
|
|
|
const sourceFiles = await getSources(ROOT_PATH, [
|
|
|
|
"*.js",
|
|
|
|
"*.ts",
|
2021-04-10 02:46:27 -04:00
|
|
|
":!:.github/mtime_cache/action.js",
|
2021-08-11 10:20:47 -04:00
|
|
|
":!:cli/tests/testdata/swc_syntax_error.ts",
|
|
|
|
":!:cli/tests/testdata/error_008_checkjs.js",
|
2022-06-08 08:03:38 -04:00
|
|
|
":!:cli/bench/http/node*.js",
|
2022-08-19 06:24:54 -04:00
|
|
|
":!:cli/bench/testdata/npm/*",
|
2022-01-18 06:58:50 -05:00
|
|
|
":!:cli/bench/testdata/express-router.js",
|
2022-08-18 08:05:02 -04:00
|
|
|
":!:cli/bench/testdata/react-dom.js",
|
2020-11-05 09:53:21 -05:00
|
|
|
":!:cli/compilers/wasm_wrap.js",
|
|
|
|
":!:cli/dts/**",
|
2021-08-11 10:20:47 -04:00
|
|
|
":!:cli/tests/testdata/encoding/**",
|
|
|
|
":!:cli/tests/testdata/error_syntax.js",
|
2022-06-18 12:44:43 -04:00
|
|
|
":!:cli/tests/testdata/fmt/**",
|
2022-08-25 20:24:18 -04:00
|
|
|
":!:cli/tests/testdata/npm/**",
|
2021-08-11 10:20:47 -04:00
|
|
|
":!:cli/tests/testdata/lint/**",
|
2022-09-19 10:32:21 -04:00
|
|
|
":!:cli/tests/testdata/run/**",
|
2021-08-11 10:20:47 -04:00
|
|
|
":!:cli/tests/testdata/tsc/**",
|
2020-11-05 09:53:21 -05:00
|
|
|
":!:cli/tsc/*typescript.js",
|
2021-12-09 17:12:21 -05:00
|
|
|
":!:cli/tsc/compiler.d.ts",
|
2021-01-05 06:07:27 -05:00
|
|
|
":!:test_util/wpt/**",
|
2020-11-05 09:53:21 -05:00
|
|
|
]);
|
|
|
|
|
|
|
|
if (!sourceFiles.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-19 19:14:20 -04:00
|
|
|
const chunks = splitToChunks(sourceFiles, `${execPath} run`.length);
|
2020-11-05 09:53:21 -05:00
|
|
|
for (const chunk of chunks) {
|
2022-07-21 04:45:15 -04:00
|
|
|
const { success } = await Deno.spawn(execPath, {
|
2022-05-18 16:00:11 -04:00
|
|
|
args: ["run", "--config=" + configFile, ...chunk],
|
|
|
|
stdout: "inherit",
|
|
|
|
stderr: "inherit",
|
2020-11-05 09:53:21 -05:00
|
|
|
});
|
2022-07-21 04:45:15 -04:00
|
|
|
if (!success) {
|
2020-11-05 09:53:21 -05:00
|
|
|
throw new Error("dlint failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-19 19:14:20 -04:00
|
|
|
// `prefer-primordials` has to apply only to files related to bootstrapping,
|
|
|
|
// which is different from other lint rules. This is why this dedicated function
|
|
|
|
// is needed.
|
|
|
|
async function dlintPreferPrimordials() {
|
|
|
|
const execPath = getPrebuiltToolPath("dlint");
|
|
|
|
console.log("prefer-primordials");
|
|
|
|
|
|
|
|
const sourceFiles = await getSources(ROOT_PATH, [
|
|
|
|
"runtime/**/*.js",
|
|
|
|
"ext/**/*.js",
|
|
|
|
"core/**/*.js",
|
|
|
|
":!:core/examples/**",
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (!sourceFiles.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const chunks = splitToChunks(sourceFiles, `${execPath} run`.length);
|
|
|
|
for (const chunk of chunks) {
|
2022-07-21 04:45:15 -04:00
|
|
|
const { success } = await Deno.spawn(execPath, {
|
2022-05-18 16:00:11 -04:00
|
|
|
args: ["run", "--rule", "prefer-primordials", ...chunk],
|
|
|
|
stdout: "inherit",
|
|
|
|
stderr: "inherit",
|
2021-08-19 19:14:20 -04:00
|
|
|
});
|
2022-07-21 04:45:15 -04:00
|
|
|
if (!success) {
|
2021-08-19 19:14:20 -04:00
|
|
|
throw new Error("prefer-primordials failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function splitToChunks(paths, initCmdLen) {
|
|
|
|
let cmdLen = initCmdLen;
|
|
|
|
const MAX_COMMAND_LEN = 30000;
|
|
|
|
const chunks = [[]];
|
|
|
|
for (const p of paths) {
|
|
|
|
if (cmdLen + p.length > MAX_COMMAND_LEN) {
|
|
|
|
chunks.push([p]);
|
|
|
|
cmdLen = initCmdLen;
|
|
|
|
} else {
|
|
|
|
chunks[chunks.length - 1].push(p);
|
|
|
|
cmdLen += p.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return chunks;
|
|
|
|
}
|
|
|
|
|
2020-11-05 09:53:21 -05:00
|
|
|
async function clippy() {
|
|
|
|
console.log("clippy");
|
|
|
|
|
|
|
|
const currentBuildMode = buildMode();
|
2022-05-18 16:00:11 -04:00
|
|
|
const cmd = ["clippy", "--all-targets", "--locked"];
|
2020-11-05 09:53:21 -05:00
|
|
|
|
|
|
|
if (currentBuildMode != "debug") {
|
|
|
|
cmd.push("--release");
|
|
|
|
}
|
|
|
|
|
2022-07-21 04:45:15 -04:00
|
|
|
const { success } = await Deno.spawn("cargo", {
|
2022-08-19 08:17:18 -04:00
|
|
|
args: [...cmd, "--", "-D", "warnings"],
|
2022-05-18 16:00:11 -04:00
|
|
|
stdout: "inherit",
|
|
|
|
stderr: "inherit",
|
2020-11-05 09:53:21 -05:00
|
|
|
});
|
2022-07-21 04:45:15 -04:00
|
|
|
if (!success) {
|
2020-11-05 09:53:21 -05:00
|
|
|
throw new Error("clippy failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
await Deno.chdir(ROOT_PATH);
|
|
|
|
|
|
|
|
let didLint = false;
|
|
|
|
|
|
|
|
if (Deno.args.includes("--js")) {
|
|
|
|
await dlint();
|
2021-08-19 19:14:20 -04:00
|
|
|
await dlintPreferPrimordials();
|
2020-11-05 09:53:21 -05:00
|
|
|
didLint = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Deno.args.includes("--rs")) {
|
|
|
|
await clippy();
|
|
|
|
didLint = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!didLint) {
|
|
|
|
await dlint();
|
2021-08-19 19:14:20 -04:00
|
|
|
await dlintPreferPrimordials();
|
2020-11-05 09:53:21 -05:00
|
|
|
await clippy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await main();
|