summaryrefslogtreecommitdiff
path: root/tools/lint.js
diff options
context:
space:
mode:
authorYusuke Tanaka <yusuktan@maguro.dev>2021-08-20 08:14:20 +0900
committerGitHub <noreply@github.com>2021-08-20 01:14:20 +0200
commit4ae57d185ea94f0217cf6234e4875cc84b4db8e8 (patch)
treebfbf3cbe33206d98c1bc8183725bd6e1c8c14f85 /tools/lint.js
parent4f322da07c73a09f004452b8e38304a632ee51aa (diff)
chore: upgrade dlint and run `prefer-primordials` rule (#11777)
Diffstat (limited to 'tools/lint.js')
-rwxr-xr-xtools/lint.js63
1 files changed, 50 insertions, 13 deletions
diff --git a/tools/lint.js b/tools/lint.js
index f5aadc77c..03339bcbe 100755
--- a/tools/lint.js
+++ b/tools/lint.js
@@ -38,19 +38,7 @@ async function dlint() {
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;
- }
- }
+ const chunks = splitToChunks(sourceFiles, `${execPath} run`.length);
for (const chunk of chunks) {
const p = Deno.run({
cmd: [execPath, "run", "--config=" + configFile, ...chunk],
@@ -63,6 +51,53 @@ async function dlint() {
}
}
+// `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) {
+ const p = Deno.run({
+ cmd: [execPath, "run", "--rule", "prefer-primordials", ...chunk],
+ });
+ const { success } = await p.status();
+ if (!success) {
+ throw new Error("prefer-primordials failed");
+ }
+ p.close();
+ }
+}
+
+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;
+}
+
async function clippy() {
console.log("clippy");
@@ -90,6 +125,7 @@ async function main() {
if (Deno.args.includes("--js")) {
await dlint();
+ await dlintPreferPrimordials();
didLint = true;
}
@@ -100,6 +136,7 @@ async function main() {
if (!didLint) {
await dlint();
+ await dlintPreferPrimordials();
await clippy();
}
}