-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmt.js
63 lines (58 loc) · 1.3 KB
/
fmt.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import util from "node:util";
export class Fmt {
/**
* @param {import("./scanner").FileScan[]} scanOutput
*/
static toStdout(scanOutput) {
return scanOutput
.flatMap((so) =>
so.findings.map((fi) =>
util.format(
"\x1b[36m%s\x1b[0m:%s \x1b[90m%s\x1b[0m",
so.file,
fi.line,
fi.comment
)
)
)
.join("\n");
}
/**
* @param {import("./scanner").FileScan[]} scanOutput
*/
static toString(scanOutput) {
return scanOutput
.flatMap((so) =>
so.findings.map((fi) => `${so.file}:${fi.line} ${fi.comment}`)
)
.join("\n");
}
/**
* @param {import("./scanner").FileScan[]} scanOutput
*/
static toJSON(scanOutput) {
let buf = [];
for (const so of scanOutput) {
for (const fi of so.findings) {
buf.push({ file: so.file, line: fi.line, comment: fi.comment });
}
}
return JSON.stringify(buf);
}
/**
* @param {import("./scanner").FileScan[]} scanOutput
*/
static toJSONL(scanOutput) {
return scanOutput
.flatMap((so) =>
so.findings.map((fi) =>
JSON.stringify({
file: so.file,
line: fi.line,
comment: fi.comment,
})
)
)
.join("\n");
}
}