Skip to content

Instantly share code, notes, and snippets.

@UltiRequiem
Created March 30, 2022 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UltiRequiem/1e5547bde091154be1a7d3c5e15f0040 to your computer and use it in GitHub Desktop.
Save UltiRequiem/1e5547bde091154be1a7d3c5e15f0040 to your computer and use it in GitHub Desktop.
Check and Lint deno code format
#!/usr/bin/env -S deno run --allow-run
const checkFormatprocess = Deno.run({
cmd: ["deno", "fmt", "--check", "."],
stdout: "null",
stderr: "null",
});
const lintProcess = Deno.run({
cmd: ["deno", "lint", "."],
stdout: "null",
stderr: "null",
});
let [{ code: checkFormatCode }, { code: lintCode }] = await Promise.all([
checkFormatprocess.status(),
lintProcess.status(),
]);
if (checkFormatCode !== 0) {
console.log("You have some formatting errors...");
if (prompt("You want to fix them?")) {
const formatProcess = Deno.run({
cmd: ["deno", "fmt", "."],
});
const { code: formatCode } = await formatProcess.status();
if (formatCode === 0) {
checkFormatCode--;
console.log("Formatting successful!");
} else {
console.log("Formatting failed!");
}
}
}
if (lintCode !== 0) {
console.log("You have linting errors, this cannot be fixed automatically.");
}
if (lintCode + checkFormatCode === 0) {
console.log("All good!");
Deno.exit(0);
}
console.log("This will not pass the continuous integration...");
Deno.exit(1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment