mirror of
https://github.com/github/codeql.git
synced 2026-04-29 02:35:15 +02:00
Java: Use the Diagnostics class in DiagnosticsReporting.qll
We shouldn't use database types/tables directly in src/
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
import java
|
||||
import semmle.code.java.Diagnostics
|
||||
|
||||
/** Gets the SARIF severity level that indicates an error. */
|
||||
private int getErrorSeverity() { result = 2 }
|
||||
@@ -10,38 +11,44 @@ private int getErrorSeverity() { result = 2 }
|
||||
/** Gets the SARIF severity level that indicates a warning. */
|
||||
private int getWarnSeverity() { result = 1 }
|
||||
|
||||
private predicate knownWarnings(@diagnostic d, string msg, int sev) {
|
||||
private predicate knownWarnings(Diagnostic d, string msg, int sev) {
|
||||
exists(string filename |
|
||||
diagnostics(d, _, 2, _, "Skipping Lombok-ed source file: " + filename, _, _) and
|
||||
d.getSeverity() = 2 and
|
||||
d.getMessage() = "Skipping Lombok-ed source file: " + filename and
|
||||
msg = "Use of Lombok detected. Skipping file: " + filename and
|
||||
sev = getWarnSeverity()
|
||||
)
|
||||
}
|
||||
|
||||
private predicate knownErrors(@diagnostic d, string msg, int sev) {
|
||||
private predicate knownErrors(Diagnostic d, string msg, int sev) {
|
||||
exists(string numErr, Location l |
|
||||
diagnostics(d, _, 6, _, numErr, _, l) and
|
||||
d.getSeverity() = 6 and
|
||||
d.getMessage() = numErr and
|
||||
d.getLocation() = l and
|
||||
msg = "Frontend errors in file: " + l.getFile().getAbsolutePath() + " (" + numErr + ")" and
|
||||
sev = getErrorSeverity()
|
||||
)
|
||||
or
|
||||
exists(string filename, Location l |
|
||||
diagnostics(d, _, 7, _, "Exception compiling file " + filename, _, l) and
|
||||
exists(string filename |
|
||||
d.getSeverity() = 7 and
|
||||
d.getMessage() = "Exception compiling file " + filename and
|
||||
msg = "Extraction incomplete in file: " + filename and
|
||||
sev = getErrorSeverity()
|
||||
)
|
||||
or
|
||||
exists(string errMsg, Location l |
|
||||
diagnostics(d, _, 8, _, errMsg, _, l) and
|
||||
exists(string errMsg |
|
||||
d.getSeverity() = 8 and
|
||||
d.getMessage() = errMsg and
|
||||
msg = "Severe error: " + errMsg and
|
||||
sev = getErrorSeverity()
|
||||
)
|
||||
}
|
||||
|
||||
private predicate unknownErrors(@diagnostic d, string msg, int sev) {
|
||||
private predicate unknownErrors(Diagnostic d, string msg, int sev) {
|
||||
not knownErrors(d, _, _) and
|
||||
exists(Location l, File f, int diagSev |
|
||||
diagnostics(d, _, diagSev, _, _, _, l) and l.getFile() = f and diagSev > 3
|
||||
exists(File f, int diagSev |
|
||||
d.getSeverity() = diagSev and
|
||||
d.getLocation().getFile() = f and diagSev > 3
|
||||
|
|
||||
exists(f.getRelativePath()) and
|
||||
msg = "Unknown errors in file: " + f.getAbsolutePath() + " (" + diagSev + ")" and
|
||||
@@ -53,7 +60,7 @@ private predicate unknownErrors(@diagnostic d, string msg, int sev) {
|
||||
* Holds if an extraction error or warning occurred that should be reported to end users,
|
||||
* with the message `msg` and SARIF severity `sev`.
|
||||
*/
|
||||
predicate reportableDiagnostics(@diagnostic d, string msg, int sev) {
|
||||
predicate reportableDiagnostics(Diagnostic d, string msg, int sev) {
|
||||
reportableWarnings(d, msg, sev) or reportableErrors(d, msg, sev)
|
||||
}
|
||||
|
||||
@@ -61,7 +68,7 @@ predicate reportableDiagnostics(@diagnostic d, string msg, int sev) {
|
||||
* Holds if an extraction error occurred that should be reported to end users,
|
||||
* with the message `msg` and SARIF severity `sev`.
|
||||
*/
|
||||
predicate reportableErrors(@diagnostic d, string msg, int sev) {
|
||||
predicate reportableErrors(Diagnostic d, string msg, int sev) {
|
||||
knownErrors(d, msg, sev) or unknownErrors(d, msg, sev)
|
||||
}
|
||||
|
||||
@@ -69,15 +76,15 @@ predicate reportableErrors(@diagnostic d, string msg, int sev) {
|
||||
* Holds if an extraction warning occurred that should be reported to end users,
|
||||
* with the message `msg` and SARIF severity `sev`.
|
||||
*/
|
||||
predicate reportableWarnings(@diagnostic d, string msg, int sev) { knownWarnings(d, msg, sev) }
|
||||
predicate reportableWarnings(Diagnostic d, string msg, int sev) { knownWarnings(d, msg, sev) }
|
||||
|
||||
/**
|
||||
* Holds if compilation unit `f` is a source file that has
|
||||
* no relevant extraction diagnostics associated with it.
|
||||
*/
|
||||
predicate successfullyExtracted(CompilationUnit f) {
|
||||
not exists(@diagnostic d, Location l |
|
||||
reportableDiagnostics(d, _, _) and diagnostics(d, _, _, _, _, _, l) and l.getFile() = f
|
||||
not exists(Diagnostic d |
|
||||
reportableDiagnostics(d, _, _) and d.getLocation().getFile() = f
|
||||
) and
|
||||
exists(f.getRelativePath()) and
|
||||
f.fromSource()
|
||||
|
||||
Reference in New Issue
Block a user