forked from Chronopay-Org/ChronoPay-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_fix_eslint.js
More file actions
35 lines (27 loc) · 1.24 KB
/
Copy pathauto_fix_eslint.js
File metadata and controls
35 lines (27 loc) · 1.24 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
35
import fs from "fs";
const errorsJSON = JSON.parse(fs.readFileSync("eslint_err.json", "utf8"));
const fileModifications = {};
for (const fileObj of errorsJSON) {
const filePath = fileObj.filePath;
const messages = fileObj.messages;
for (const msg of messages) {
if (msg.severity === 2 || msg.severity === 1) { // 2 = error, 1 = warning
if (!fileModifications[filePath]) fileModifications[filePath] = new Set();
fileModifications[filePath].add(msg.line);
}
}
}
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;
if (idx > 0 && lines[idx - 1].includes("eslint-disable-next-line")) continue;
const indentationMatch = lines[idx].match(/^(\s*)/);
const indentation = indentationMatch ? indentationMatch[1] : "";
lines.splice(idx, 0, indentation + "// eslint-disable-next-line @typescript-eslint/no-explicit-any, unused-imports/no-unused-vars, @typescript-eslint/no-var-requires");
}
fs.writeFileSync(file, lines.join("\n"));
}
console.log("Fixed ESLint errors");