From 4ae57d185ea94f0217cf6234e4875cc84b4db8e8 Mon Sep 17 00:00:00 2001 From: Yusuke Tanaka Date: Fri, 20 Aug 2021 08:14:20 +0900 Subject: [PATCH] chore: upgrade dlint and run `prefer-primordials` rule (#11777) --- .dlint.json | 4 +- ext/websocket/02_websocketstream.js | 1 + runtime/js/99_main.js | 2 + third_party | 2 +- tools/lint.js | 63 +++++++++++++++++++++++------ 5 files changed, 57 insertions(+), 15 deletions(-) diff --git a/.dlint.json b/.dlint.json index afd6758d5cfb6..448cc2d6050ff 100644 --- a/.dlint.json +++ b/.dlint.json @@ -4,6 +4,8 @@ "include": [ "ban-untagged-todo" ], - "exclude": [] + "exclude": [ + "no-invalid-triple-slash-reference" + ] } } diff --git a/ext/websocket/02_websocketstream.js b/ext/websocket/02_websocketstream.js index 6290d94a02b07..4e901f53aabe0 100644 --- a/ext/websocket/02_websocketstream.js +++ b/ext/websocket/02_websocketstream.js @@ -22,6 +22,7 @@ PromisePrototypeCatch, Uint8Array, TypeError, + Error, } = window.__bootstrap.primordials; webidl.converters.WebSocketStreamOptions = webidl.createDictionaryConverter( diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index b1f7d1473b861..af6309338c59e 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -22,6 +22,7 @@ delete Object.prototype.__proto__; SymbolFor, SymbolIterator, PromisePrototypeThen, + TypeError, } = window.__bootstrap.primordials; const util = window.__bootstrap.util; const eventTarget = window.__bootstrap.eventTarget; @@ -228,6 +229,7 @@ delete Object.prototype.__proto__; } else { prepareStackTrace = core.createPrepareStackTrace(); } + // deno-lint-ignore prefer-primordials Error.prepareStackTrace = prepareStackTrace; } diff --git a/third_party b/third_party index 6c449eaecb078..084660078bfd4 160000 --- a/third_party +++ b/third_party @@ -1 +1 @@ -Subproject commit 6c449eaecb0783b06003b5eecd2893bd2617d66e +Subproject commit 084660078bfd4b16993e5ef6ea7d099ad6d0cf55 diff --git a/tools/lint.js b/tools/lint.js index f5aadc77c8d15..03339bcbe49ee 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(); } }