-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoutputParser.ts
More file actions
37 lines (31 loc) · 1007 Bytes
/
outputParser.ts
File metadata and controls
37 lines (31 loc) · 1007 Bytes
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
36
37
import { PackwerkOutput, PackwerkFile } from './packwerkOutput';
const regex = /^(?<file>[^\n]*?):(?<row>\d+):(?<column>\d+)$(?<message>.*?::(?<symbol>.*?)['| ].*?)^\s?$/gms;
export function parseOutput(str: string): PackwerkOutput {
try {
return JSON.parse(str);
} catch {
const files = new Map<string, PackwerkFile>();
let arr: RegExpExecArray;
while ((arr = regex.exec(str)) !== null) {
// eslint-disable-next-line no-console
console.log('[DEBUG] Parsed regular expression', arr);
const file = arr[1];
const line = Number(arr[2]);
const column = Number(arr[3]);
const message = arr[4].trim();
const symbol = arr[5];
if (!files.has(file)) { files.set(file, { path: file, violations: [] }); }
files.get(file)!.violations.push({
message,
location: {
line,
column,
length: symbol.length,
},
});
}
return {
files: Array.from(files.values()),
};
}
}