Repository navigation
Expand file tree
/
Copy pathsarif.ts
More file actions
69 lines (65 loc) · 1.68 KB
/
Copy pathsarif.ts
File metadata and controls
69 lines (65 loc) · 1.68 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
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
64
65
66
67
68
69
import { TOOL_VERSION, type MarkscrubReport, type BatchReport } from "./types.js";
interface SarifResult {
ruleId: string;
level: "error" | "warning" | "note";
message: { text: string };
locations: Array<{
physicalLocation: {
artifactLocation: { uri: string };
};
}>;
properties?: Record<string, unknown>;
}
/** Convert one or more markscrub reports into SARIF 2.1.0. */
export function toSarif(
reports: MarkscrubReport[],
options: { failAsError?: boolean } = {},
): object {
const results: SarifResult[] = [];
for (const report of reports) {
for (const finding of report.findings) {
results.push({
ruleId: `${finding.kind}.${finding.code}`,
level: options.failAsError
? "error"
: finding.verifiable
? "warning"
: "note",
message: { text: finding.message },
locations: [
{
physicalLocation: {
artifactLocation: { uri: report.input },
},
},
],
properties: {
verifiable: finding.verifiable,
count: finding.count,
action: report.action,
},
});
}
}
return {
$schema:
"https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
version: "2.1.0",
runs: [
{
tool: {
driver: {
name: "markscrub",
version: TOOL_VERSION,
informationUri: "https://github.com/anshaneja5/markscrub",
rules: [],
},
},
results,
},
],
};
}
export function batchToSarif(batch: BatchReport): object {
return toSarif(batch.files);
}