2020-11-05 09:53:21 -05:00
|
|
|
#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run
|
2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 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";
|
2023-01-13 13:42:15 -05:00
|
|
|
import { checkCopyright } from "./copyright_checker.js";
|
|
|
|
|
|
|
|
let didLint = false;
|
|
|
|
|
|
|
|
if (Deno.args.includes("--js")) {
|
|
|
|
await dlint();
|
|
|
|
await dlintPreferPrimordials();
|
|
|
|
didLint = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Deno.args.includes("--rs")) {
|
|
|
|
await clippy();
|
|
|
|
didLint = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!didLint) {
|
2023-03-15 22:39:40 -04:00
|
|
|
await Promise.all([
|
|
|
|
dlint(),
|
|
|
|
// todo(dsherret): re-enable
|
|
|
|
// dlintPreferPrimordials(),
|
|
|
|
checkCopyright(),
|
|
|
|
clippy(),
|
|
|
|
]);
|
2023-01-13 13:42:15 -05:00
|
|
|
}
|
2020-11-05 09:53:21 -05:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
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",
|
2022-11-25 18:29:48 -05:00
|
|
|
":!:cli/tsc/dts/**",
|
2021-08-11 10:20:47 -04:00
|
|
|
":!:cli/tests/testdata/encoding/**",
|
|
|
|
":!:cli/tests/testdata/error_syntax.js",
|
2023-03-22 10:15:53 -04:00
|
|
|
":!:cli/tests/testdata/file_extensions/ts_with_js_extension.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);
|
2023-03-15 22:39:40 -04:00
|
|
|
const pending = [];
|
2020-11-05 09:53:21 -05:00
|
|
|
for (const chunk of chunks) {
|
2022-12-01 10:51:47 -05:00
|
|
|
const cmd = new Deno.Command(execPath, {
|
2023-01-13 13:42:15 -05:00
|
|
|
cwd: ROOT_PATH,
|
2022-05-18 16:00:11 -04:00
|
|
|
args: ["run", "--config=" + configFile, ...chunk],
|
2023-03-15 22:39:40 -04:00
|
|
|
// capture to not conflict with clippy output
|
|
|
|
stderr: "piped",
|
2020-11-05 09:53:21 -05:00
|
|
|
});
|
2023-03-15 22:39:40 -04:00
|
|
|
pending.push(
|
|
|
|
cmd.output().then(({ stderr, code }) => {
|
|
|
|
if (code > 0) {
|
|
|
|
const decoder = new TextDecoder();
|
|
|
|
console.log("\n------ dlint ------");
|
|
|
|
console.log(decoder.decode(stderr));
|
|
|
|
throw new Error("dlint failed");
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
);
|
2020-11-05 09:53:21 -05:00
|
|
|
}
|
2023-03-15 22:39:40 -04:00
|
|
|
await Promise.all(pending);
|
2020-11-05 09:53:21 -05:00
|
|
|
}
|
|
|
|
|
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");
|
|
|
|
const sourceFiles = await getSources(ROOT_PATH, [
|
|
|
|
"runtime/**/*.js",
|
|
|
|
"ext/**/*.js",
|
2023-01-26 06:26:42 -05:00
|
|
|
"core/*.js",
|
|
|
|
":!:core/*_test.js",
|
2021-08-19 19:14:20 -04:00
|
|
|
":!:core/examples/**",
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (!sourceFiles.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const chunks = splitToChunks(sourceFiles, `${execPath} run`.length);
|
|
|
|
for (const chunk of chunks) {
|
2022-12-01 10:51:47 -05:00
|
|
|
const cmd = new Deno.Command(execPath, {
|
2023-01-13 13:42:15 -05:00
|
|
|
cwd: ROOT_PATH,
|
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-12-01 10:51:47 -05:00
|
|
|
const { code } = await cmd.output();
|
|
|
|
|
|
|
|
if (code > 0) {
|
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() {
|
|
|
|
const currentBuildMode = buildMode();
|
2023-03-10 07:07:28 -05:00
|
|
|
const cmd = ["clippy", "--all-targets", "--all-features", "--locked"];
|
2020-11-05 09:53:21 -05:00
|
|
|
|
|
|
|
if (currentBuildMode != "debug") {
|
|
|
|
cmd.push("--release");
|
|
|
|
}
|
|
|
|
|
2022-12-01 10:51:47 -05:00
|
|
|
const cargoCmd = new Deno.Command("cargo", {
|
2023-01-13 13:42:15 -05:00
|
|
|
cwd: ROOT_PATH,
|
2022-11-10 06:53:31 -05: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-12-01 10:51:47 -05:00
|
|
|
const { code } = await cargoCmd.output();
|
|
|
|
|
|
|
|
if (code > 0) {
|
2020-11-05 09:53:21 -05:00
|
|
|
throw new Error("clippy failed");
|
|
|
|
}
|
|
|
|
}
|