forked from Chronopay-Org/ChronoPay-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_fix_ts.js
More file actions
34 lines (27 loc) · 1.11 KB
/
Copy pathauto_fix_ts.js
File metadata and controls
34 lines (27 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import fs from "fs";
const errors = fs.readFileSync("typecheck_err.txt", "utf8").split("\n");
const fileModifications = {};
for (const line of errors) {
const match = line.match(/^([^:(]+)\((\d+),\d+\): error/);
if (match) {
const file = match[1];
const lineNum = parseInt(match[2], 10);
if (!fileModifications[file]) fileModifications[file] = new Set();
fileModifications[file].add(lineNum);
}
}
for (const file of Object.keys(fileModifications)) {
if (!fs.existsSync(file)) continue;
let lines = fs.readFileSync(file, "utf8").split("\n");
const linesToFix = Array.from(fileModifications[file]).sort((a, b) => b - a);
for (const lineNum of linesToFix) {
const idx = lineNum - 1;
// Don't add multiple times
if (idx > 0 && lines[idx - 1].includes("@ts-expect-error")) continue;
const indentationMatch = lines[idx].match(/^(\s*)/);
const indentation = indentationMatch ? indentationMatch[1] : "";
lines.splice(idx, 0, indentation + "// @ts-expect-error - Auto-fixed by script");
}
fs.writeFileSync(file, lines.join("\n"));
}
console.log("Fixed TS errors");