Created
November 5, 2021 06:47
-
-
Save bencooper222/50487b16ce4e7dee157ac90330d368e8 to your computer and use it in GitHub Desktop.
Reads a set of ts compiler errors and inserts ts-expect-error before all of them (has known off by one flaws)
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 { readFileSync, writeFileSync } from 'fs'; | |
const errors = readFileSync('./out.txt', 'utf-8') | |
.split('\n') | |
.filter(el => !el.startsWith(' ')); | |
const parsedErrors = []; | |
for (const err of errors) { | |
const [file] = err.split(':'); | |
const [path, lineNumRawDetails] = file.split('('); | |
const parsedStringLineDetails = lineNumRawDetails.split(','); | |
parsedStringLineDetails[1] = parsedStringLineDetails[1].slice(0, -1); | |
const parsedNumberedLineDetails = parsedStringLineDetails.map(el => Number(el)); | |
const fullErrorDetails = { | |
file: path, | |
line: parsedNumberedLineDetails[0], | |
column: parsedNumberedLineDetails[1], | |
}; | |
parsedErrors.push(fullErrorDetails); | |
} | |
const fileTracker = {}; | |
for (const err of parsedErrors) { | |
const file = readFileSync(err.file, 'utf8').split('\n'); | |
file.splice(err.line - 1 + (fileTracker[err.file] ?? 0), 0, `// @ts-expect-error`); | |
const joined = file.join('\n'); | |
writeFileSync(err.file, joined, { encoding: 'utf8' }); | |
if (fileTracker[err.file]) fileTracker[err.file]++; | |
else fileTracker[err.file] = 1; | |
console.log('modded ' + err.file + ' ' + err.line); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment