Skip to content

Commit a87cf5a

Browse files
committed
C#: Include metrics in the database quality diagnostics.
1 parent 2100dc1 commit a87cf5a

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

csharp/ql/src/Telemetry/DatabaseQualityDiagnostics.ql

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,37 @@
88
import csharp
99
import DatabaseQuality
1010

11+
private int getThreshold() { result = 85 }
12+
1113
private newtype TDbQualityDiagnostic =
12-
TTheDbQualityDiagnostic() {
13-
exists(float percentageGood |
14-
CallTargetStatsReport::percentageOfOk(_, percentageGood)
15-
or
16-
ExprTypeStatsReport::percentageOfOk(_, percentageGood)
17-
|
18-
percentageGood < 95
19-
)
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()
2018
}
2119

2220
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)
28+
}
29+
30+
private string getDbHealth() {
31+
result =
32+
callMsg + ": " + callTargetOk.floor() + ". " + exprMsg + ": " + exprTypeOk.floor() + ". "
33+
}
34+
2335
string toString() {
2436
result =
2537
"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# "
38+
"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+
"Addressing these issues is advisable to avoid false-positives or missing results. If they cannot be addressed, consider scanning C# "
3142
+
3243
"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)."
3344
}

0 commit comments

Comments
 (0)