diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-11-05 15:53:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-05 15:53:21 +0100 |
commit | 791119d4af1066b20fa2b5bf8fc82d04d843d51d (patch) | |
tree | 94890756f4380fb2c1d8abd92af66128533a1535 /tools/lint.js | |
parent | e7cfd90b0f72874aa1535a382df32dce28bd587a (diff) |
build: rewrite tools/ scripts to deno (#8247)
This commit rewrites scripts in "tools/" directory
to use Deno instead of Python. In return it allows
to remove huge number of Python packages in "third_party/".
Diffstat (limited to 'tools/lint.js')
-rwxr-xr-x | tools/lint.js | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/tools/lint.js b/tools/lint.js new file mode 100755 index 000000000..18de2aef3 --- /dev/null +++ b/tools/lint.js @@ -0,0 +1,102 @@ +#!/usr/bin/env -S deno run --unstable --allow-write --allow-read --allow-run +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +import { + buildMode, + getPrebuiltToolPath, + getSources, + ROOT_PATH, +} from "./util.js"; + +async function dlint() { + const execPath = getPrebuiltToolPath("dlint"); + console.log("dlint"); + + const sourceFiles = await getSources(ROOT_PATH, [ + "*.js", + "*.ts", + ":!:cli/tests/swc_syntax_error.ts", + ":!:cli/tests/038_checkjs.js", + ":!:cli/tests/error_008_checkjs.js", + ":!:std/**/testdata/*", + ":!:std/**/node_modules/*", + ":!:cli/bench/node*.js", + ":!:cli/compilers/wasm_wrap.js", + ":!:cli/dts/**", + ":!:cli/tests/encoding/**", + ":!:cli/tests/error_syntax.js", + ":!:cli/tests/lint/**", + ":!:cli/tests/tsc/**", + ":!:cli/tsc/*typescript.js", + ]); + + if (!sourceFiles.length) { + return; + } + + const MAX_COMMAND_LEN = 30000; + const preCommand = [execPath, "run"]; + const chunks = [[]]; + let cmdLen = preCommand.join(" ").length; + for (const f of sourceFiles) { + if (cmdLen + f.length > MAX_COMMAND_LEN) { + chunks.push([f]); + cmdLen = preCommand.join(" ").length; + } else { + chunks[chunks.length - 1].push(f); + cmdLen = preCommand.join(" ").length; + } + } + for (const chunk of chunks) { + const p = Deno.run({ + cmd: [execPath, "run", ...chunk], + }); + const { success } = await p.status(); + if (!success) { + throw new Error("dlint failed"); + } + p.close(); + } +} + +async function clippy() { + console.log("clippy"); + + const currentBuildMode = buildMode(); + const cmd = ["cargo", "clippy", "--all-targets", "--locked"]; + + if (currentBuildMode != "debug") { + cmd.push("--release"); + } + + const p = Deno.run({ + cmd: [...cmd, "--", "-D", "clippy::all"], + }); + const { success } = await p.status(); + if (!success) { + throw new Error("clippy failed"); + } + p.close(); +} + +async function main() { + await Deno.chdir(ROOT_PATH); + + let didLint = false; + + if (Deno.args.includes("--js")) { + await dlint(); + didLint = true; + } + + if (Deno.args.includes("--rs")) { + await clippy(); + didLint = true; + } + + if (!didLint) { + await dlint(); + await clippy(); + } +} + +await main(); |