-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathcodeql-quick-stats.ts
More file actions
79 lines (67 loc) · 2.11 KB
/
codeql-quick-stats.ts
File metadata and controls
79 lines (67 loc) · 2.11 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
70
71
72
73
74
75
76
77
78
79
import * as fs from 'fs';
import * as path from 'path';
// Define the interfaces for the SARIF structure
interface SarifResult {
ruleId: string;
}
interface SarifRun {
tool: object;
results: SarifResult[];
}
interface SarifLog {
$schema: string;
version: string;
runs: SarifRun[];
}
// Function to read and parse the SARIF file
function readSarifFile(filePath: string): SarifLog {
const data = fs.readFileSync(filePath, 'utf-8');
return JSON.parse(data) as SarifLog;
}
// Function to display the total number of detected warnings
function displayTotalWarnings(results: SarifResult[]): void {
console.log(`Total number of detected warnings: ${results.length}`);
}
// Function to display all distinct ruleIds
function displayDistinctRuleIds(results: SarifResult[]): void {
const ruleIds = new Set(results.map(result => result.ruleId));
console.log('Distinct ruleIds:');
ruleIds.forEach(ruleId => console.log(ruleId));
}
// Function to display count of distinct ruleIds
function displayCountDistinctRuleIds(results: SarifResult[]): void {
const ruleIds = new Set(results.map(result => result.ruleId));
console.log(`Count of distinct ruleIds: ${ruleIds.size}`);
}
// Main function to handle command-line arguments and execute corresponding functions
function main() {
if (process.argv.length < 4) {
console.error('Usage: npx ts-node codeql-quick-stats.ts <file> <-t|-n|-d>');
process.exit(1);
}
const filePath = path.resolve(process.argv[2]);
const option = process.argv[3];
const sarifLog = readSarifFile(filePath);
// Assuming we're interested in the results from the first run
if (sarifLog.runs.length === 0) {
console.error('No runs found in the SARIF file.');
process.exit(1);
}
const results = sarifLog.runs[0].results;
switch (option) {
case '-t':
displayTotalWarnings(results);
break;
case '-n':
displayDistinctRuleIds(results);
break;
case '-d':
displayCountDistinctRuleIds(results);
break;
default:
console.error('Invalid option. Use -t, -n, or -d.');
process.exit(1);
}
}
// Execute the main function
main();