Created
August 29, 2024 17:04
-
-
Save irbull/42d485dca9a1a9707f3354f17c42862d to your computer and use it in GitHub Desktop.
Generate error message candidates
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
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", | |
]; | |
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