-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy patheslint-to-sarif.mjs
More file actions
56 lines (50 loc) · 1.56 KB
/
eslint-to-sarif.mjs
File metadata and controls
56 lines (50 loc) · 1.56 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
import { readFileSync, writeFileSync } from "fs";
import process from "node:process";
try {
const input = readFileSync(0, "utf8");
if (!input) {
console.error("Keine Daten von ESLint empfangen.");
process.exit(1);
}
const eslintJson = JSON.parse(input);
// Zählen, wie viele echte Meldungen wir haben
const totalMessages = eslintJson.reduce((sum, file) => sum + file.messages.length, 0);
console.log(`Gefundene ESLint-Meldungen: ${totalMessages}`);
const sarifOutput = {
$schema: "https://www.schemastore.org/sarif-2.1.0.json",
version: "2.1.0",
runs: [{
tool: {
driver: {
name: "ESLint",
informationUri: "https://eslint.org"
}
},
results: eslintJson.flatMap(file => file.messages.map(msg => ({
ruleId: msg.ruleId || "generic",
level: 2 === msg.severity ? "error" : "note",
message: { text: msg.message },
locations: [{
physicalLocation: {
artifactLocation: {
uri: file.filePath.replace(process.cwd() + "/", "")
},
region: {
startLine: msg.line || 1,
startColumn: msg.column || 1
}
}
}]
})))
}]
};
writeFileSync("results.sarif", JSON.stringify(sarifOutput, null, 2));
if (totalMessages > 0) {
console.log("✅ results.sarif mit Ergebnissen erstellt.");
} else {
console.log("ℹ️ Keine Fehler gefunden. results.sarif ist leer (planmäßig).");
}
} catch (err) {
console.error("Fehler:", err.message);
process.exit(1);
}