forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtractorInformation.ql
More file actions
97 lines (85 loc) · 3.11 KB
/
Copy pathExtractorInformation.ql
File metadata and controls
97 lines (85 loc) · 3.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* @name Java extraction information
* @description Information about the extraction for a Java database
* @kind metric
* @tags summary telemetry
* @id java/telemetry/extraction-information
*/
import java
import semmle.code.java.Diagnostics
predicate compilationInfo(string key, int value) {
exists(Compilation c, string infoKey |
key = infoKey + ": " + c.getInfo(infoKey) and
value = 1
)
}
predicate fileCount(string key, int value) {
key = "Number of files" and
value = strictcount(File f)
}
predicate fileCountByExtension(string key, int value) {
exists(string extension |
key = "Number of files with extension " + extension and
value = strictcount(File f | f.getExtension() = extension)
)
}
predicate totalNumberOfLines(string key, int value) {
key = "Total number of lines" and
value = strictsum(File f | any() | f.getTotalNumberOfLines())
}
predicate numberOfLinesOfCode(string key, int value) {
key = "Number of lines of code" and
value = strictsum(File f | any() | f.getNumberOfLinesOfCode())
}
predicate totalNumberOfLinesByExtension(string key, int value) {
exists(string extension |
key = "Total number of lines with extension " + extension and
value = strictsum(File f | f.getExtension() = extension | f.getTotalNumberOfLines())
)
}
predicate numberOfLinesOfCodeByExtension(string key, int value) {
exists(string extension |
key = "Number of lines of code with extension " + extension and
value = strictsum(File f | f.getExtension() = extension | f.getNumberOfLinesOfCode())
)
}
predicate extractorDiagnostics(string key, int value) {
exists(string extractor, int severity |
key = "Number of diagnostics from " + extractor + " with severity " + severity.toString() and
value =
strictcount(Diagnostic d | d.getGeneratedBy() = extractor and d.getSeverity() = severity)
)
}
/*
* Just counting the diagnostics doesn't give the full picture, as
* CODEQL_EXTRACTOR_KOTLIN_DIAGNOSTIC_LIMIT means that some diagnostics
* will be suppressed. In that case, we need to look for the
* suppression message, uncount those that did get emitted, uncount the
* suppression message itself, and then add on the full count.
*/
predicate extractorTotalDiagnostics(string key, int value) {
exists(string extractor, string limitRegex |
limitRegex = "Total of ([0-9]+) diagnostics \\(reached limit of ([0-9]+)\\).*" and
key = "Total number of diagnostics from " + extractor and
value =
strictcount(Diagnostic d | d.getGeneratedBy() = extractor) +
sum(Diagnostic d |
d.getGeneratedBy() = extractor
|
d.getMessage().regexpCapture(limitRegex, 1).toInt() -
d.getMessage().regexpCapture(limitRegex, 2).toInt() - 1
)
)
}
from string key, int value
where
compilationInfo(key, value) or
fileCount(key, value) or
fileCountByExtension(key, value) or
totalNumberOfLines(key, value) or
numberOfLinesOfCode(key, value) or
totalNumberOfLinesByExtension(key, value) or
numberOfLinesOfCodeByExtension(key, value) or
extractorDiagnostics(key, value) or
extractorTotalDiagnostics(key, value)
select key, value