Skip to content

Commit d9e82cd

Browse files
committed
C#: Include metrics in the database quality diagnostics.
1 parent 64d68fe commit d9e82cd

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

csharp/ql/src/Telemetry/DatabaseQualityDiagnostics.ql

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,34 @@ import csharp
99
import DatabaseQuality
1010

1111
private newtype TDbQualityDiagnostic =
12-
TTheDbQualityDiagnostic() {
13-
exists(float percentageGood |
14-
CallTargetStatsReport::percentageOfOk(_, percentageGood)
15-
or
16-
ExprTypeStatsReport::percentageOfOk(_, percentageGood)
17-
|
18-
percentageGood < 95
19-
)
12+
TTheDbQualityDiagnostic(string callMsg, float callTargetOk, string exprMsg, float exprTypeOk) {
13+
CallTargetStatsReport::percentageOfOk(callMsg, callTargetOk) and
14+
ExprTypeStatsReport::percentageOfOk(exprMsg, exprTypeOk) and
15+
[callTargetOk, exprTypeOk] < 95
2016
}
2117

2218
class DbQualityDiagnostic extends TDbQualityDiagnostic {
19+
private string callMsg;
20+
private float callTargetOk;
21+
private float exprTypeOk;
22+
private string exprMsg;
23+
24+
DbQualityDiagnostic() {
25+
this = TTheDbQualityDiagnostic(callMsg, callTargetOk, exprMsg, exprTypeOk)
26+
}
27+
28+
private string getDbHealth() {
29+
result =
30+
callMsg + ": " + callTargetOk.floor() + ". " + exprMsg + ": " + exprTypeOk.floor() + ". "
31+
}
32+
2333
string toString() {
2434
result =
2535
"Scanning C# code completed successfully, but the scan encountered issues. " +
26-
"This may be caused by problems identifying dependencies or use of generated source code, among other reasons -- "
27-
+
28-
"see other CodeQL diagnostics reported on the CodeQL status page for more details of possible causes. "
29-
+
30-
"Addressing these warnings is advisable to avoid false-positive or missing results. If they cannot be addressed, consider scanning C# "
36+
"This may be caused by problems identifying dependencies or use of generated source code. " +
37+
"Some metrics of the database quality are: " + this.getDbHealth() +
38+
"Both of these metrics should ideally be above 95%. " +
39+
"Addressing these issues is advisable to avoid false-positives or missing results. If they cannot be addressed, consider scanning C# "
3140
+
3241
"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)."
3342
}

0 commit comments

Comments
 (0)