Skip to content

Commit 827ea4c

Browse files
committed
C#: Address review comments.
1 parent 7bf0529 commit 827ea4c

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

csharp/ql/src/Telemetry/DatabaseQualityDiagnostics.ql

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,38 @@
88
import csharp
99
import DatabaseQuality
1010

11-
private int getThreshold() { result = 85 }
11+
private predicate diagnostic(string msg, float value, float threshold) {
12+
CallTargetStatsReport::percentageOfOk(msg, value) and
13+
threshold = 85
14+
or
15+
ExprTypeStatsReport::percentageOfOk(msg, value) and
16+
threshold = 85
17+
}
1218

1319
private newtype TDbQualityDiagnostic =
14-
TTheDbQualityDiagnostic(string callMsg, float callTargetOk, string exprMsg, float exprTypeOk) {
15-
CallTargetStatsReport::percentageOfOk(callMsg, callTargetOk) and
16-
ExprTypeStatsReport::percentageOfOk(exprMsg, exprTypeOk) and
17-
[callTargetOk, exprTypeOk] < getThreshold()
18-
}
19-
20-
class DbQualityDiagnostic extends TDbQualityDiagnostic {
21-
private string callMsg;
22-
private float callTargetOk;
23-
private float exprTypeOk;
24-
private string exprMsg;
25-
26-
DbQualityDiagnostic() {
27-
this = TTheDbQualityDiagnostic(callMsg, callTargetOk, exprMsg, exprTypeOk)
20+
TTheDbQualityDiagnostic() {
21+
exists(float percentageGood, float threshold |
22+
diagnostic(_, percentageGood, threshold) and
23+
percentageGood < threshold
24+
)
2825
}
2926

30-
private string getDbHealth() {
31-
result =
32-
callMsg + ": " + callTargetOk.floor() + ". " + exprMsg + ": " + exprTypeOk.floor() + ". "
33-
}
27+
private string getDbHealth() {
28+
result =
29+
strictconcat(string msg, float value, float threshold |
30+
diagnostic(msg, value, threshold)
31+
|
32+
msg + ": " + value.floor() + " % (threshold " + threshold.floor() + " %)", ". "
33+
)
34+
}
3435

36+
class DbQualityDiagnostic extends TDbQualityDiagnostic {
3537
string toString() {
3638
result =
3739
"Scanning C# code completed successfully, but the scan encountered issues. " +
3840
"This may be caused by problems identifying dependencies or use of generated source code. " +
39-
"Some metrics of the database quality are: " + this.getDbHealth() +
40-
"Both of these metrics should ideally be above " + getThreshold() + ". " +
41+
"Some metrics of the database quality are: " + getDbHealth() + ". " +
42+
"Ideally these metrics should be above their thresholds. " +
4143
"Addressing these issues is advisable to avoid false-positives or missing results. If they cannot be addressed, consider scanning C# "
4244
+
4345
"using either the `autobuild` or `manual` [build modes](https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages#comparison-of-the-build-modes)."

0 commit comments

Comments
 (0)