Skip to content

Instantly share code, notes, and snippets.

@irbull
Last active August 29, 2024 17:08
Show Gist options
  • Save irbull/a16232d1a96ee3023501baf48b17a7e9 to your computer and use it in GitHub Desktop.
Save irbull/a16232d1a96ee3023501baf48b17a7e9 to your computer and use it in GitHub Desktop.
import { dirname, join } from "jsr:@std/path/";
import { WalkEntry, walkSync } from "jsr:@std/fs/walk";
const ROOT = <PATH_TO_DENO>;
const DIR_SKIP_LIST = [
"/node_modules/",
"/testdata/",
"/tests/",
"/.github/",
"/bench",
"/tsc",
];
// Created `ts_files.txt` first using
// find . -name "*.ts" > ts_files.txt (base) 1200ms  Thu 29 Aug 09:00:07 2024
// find . -name "*.js" >> ts_files.txt
const tsFiles = Deno.readTextFileSync("./ts_files.txt").split("\n");
const tsDirs = tsFiles.map((f) => dirname(f)).filter(shouldSkip).sort().reduce(
(prev: string[], curr) => {
if (prev.indexOf(curr) < 0) prev.push(curr);
return prev;
},
[],
);
console.log(`| Folder | Throws | Status | PR |`);
console.log(`| --- | --- | --- | --- |`);
for (const dir of tsDirs) {
const errors = await countErrors(dir);
if (errors === 0) {
console.log(`| ${dir} | ${errors} | ✅ | No obvious problems found|`);
} else {
console.log(`| ${dir} | ${errors} | ⛔| |`);
}
}
function shouldSkip(dir: string): boolean {
for (const skip of DIR_SKIP_LIST) {
if (dir.includes(skip)) return false;
}
return !(dir === ".");
}
function countErrors(path: string): number {
let errors = 0;
const paths = walkSync(join(ROOT, path), { maxDepth: 1 })
.map((
f: WalkEntry,
) => f.path);
for (const file of paths) {
if (file.endsWith(".ts") || file.endsWith(".js")) {
errors += countErrorsInFile(file);
}
}
return errors;
}
function countErrorsInFile(path: string): number {
const content = Deno.readTextFileSync(path).split("\n");
let errors = 0;
for (const line of content) {
if (line.includes("throw")) {
errors++;
}
}
return errors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment