Created
March 30, 2022 16:23
-
-
Save UltiRequiem/1e5547bde091154be1a7d3c5e15f0040 to your computer and use it in GitHub Desktop.
Check and Lint deno code format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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