Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade dlint and run prefer-primordials #11777

Merged
merged 5 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .dlint.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"include": [
"ban-untagged-todo"
],
"exclude": []
"exclude": [
"no-invalid-triple-slash-reference"
]
Comment on lines +7 to +9
Copy link
Member Author

@magurotuna magurotuna Aug 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, no-invalid-triple-slash-reference rule is for Deno users, not for the internal code of Deno, so I added it here. Please correct me if I'm wrong.
https://lint.deno.land/#no-invalid-triple-slash-reference

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct

}
}
1 change: 1 addition & 0 deletions ext/websocket/02_websocketstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
PromisePrototypeCatch,
Uint8Array,
TypeError,
Error,
} = window.__bootstrap.primordials;

webidl.converters.WebSocketStreamOptions = webidl.createDictionaryConverter(
Expand Down
2 changes: 2 additions & 0 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -228,6 +229,7 @@ delete Object.prototype.__proto__;
} else {
prepareStackTrace = core.createPrepareStackTrace();
}
// deno-lint-ignore prefer-primordials
Error.prepareStackTrace = prepareStackTrace;
Comment on lines +232 to 233
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Node.js, Error.prepareStackTrace is skipped linting because of the config. But deno_lint doesn't support it right now, so just added an ignore directive here for the moment.

}

Expand Down
2 changes: 1 addition & 1 deletion third_party
63 changes: 50 additions & 13 deletions tools/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
});
bartlomieju marked this conversation as resolved.
Show resolved Hide resolved
const { success } = await p.status();
if (!success) {
throw new Error("prefer-primordials failed");
}
p.close();
}
}
Comment on lines +57 to +83
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think prefer-primordials should apply only to the code related to bootstrapping, so I created another function where only this rule is run.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, please add a comment explaining that

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍 0cf3bfb


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");

Expand Down Expand Up @@ -90,6 +125,7 @@ async function main() {

if (Deno.args.includes("--js")) {
await dlint();
await dlintPreferPrimordials();
didLint = true;
}

Expand All @@ -100,6 +136,7 @@ async function main() {

if (!didLint) {
await dlint();
await dlintPreferPrimordials();
await clippy();
}
}
Expand Down