tsc-输出-参数
从 tsc 输出到结构化的 JSON 格式分析出错误 .
转换 tsc 输出 :
src/actions.ts(691,20): error TS7006: Parameter 'error' implicitly has an 'any' type.
给JSON:
[
{
"type": "Item",
"value": {
"path": {
"type": "Path",
"value": "src/actions.ts"
},
"cursor": {
"type": "Cursor",
"value": {
"line": 691,
"col": 20
}
},
"tsError": {
"type": "TsError",
"value": {
"type": "error",
"errorString": "TS7006"
}
},
"message": {
"type": "Message",
"value": " Parameter 'error' implicitly has an 'any' type.\n"
}
}
}
]
安装
安装方式 npm i -g @aivenio/tsc-output-parser。 。 。 .
使用量
国 际
通过临时文件 :
tsc --strict --noEmit > ts.out
tsc-output-parser ts.out > errors.json
通过管道:
tsc --strict --noEmit | tsc-output-parser
API 密码
import { parse } from '@aivenio/tsc-output-parser';
const input = `
src/actions.ts(691,20): error TS7006: Parameter 'error' implicitly has an 'any' type.
`;
const errors = parse(input);
测试示例
要转换 real.txt 测试示例, 克隆 repo并运行 :
npm install
npm run peg
./node_modules/.bin/ts-node src/cli.ts test/inputs/real.txt
动机
为了使用严格的类型将我们的代码基础迁移到 TypeScript,我们建造了 追踪我们的进展 解析可能已经做了很多 (也许 比较容易) 方法,但它作为一个很好的例子 使用 国家 来解析文本.