Swift: add an internal query-suite for listing all the compiler errors

This commit is contained in:
Alex Denisov
2022-11-08 14:33:50 +01:00
parent 8756989b4b
commit a1fa424ec1
3 changed files with 41 additions and 4 deletions

View File

@@ -1,5 +1,31 @@
private import codeql.swift.generated.Diagnostics
class Diagnostics extends Generated::Diagnostics {
override string toString() { result = getText() }
override string toString() { result = getSeverity() + ": " + getText() }
string getSeverity() {
getKind() = 1 and result = "error"
or
getKind() = 2 and result = "warning"
or
getKind() = 3 and result = "note"
or
getKind() = 4 and result = "remark"
}
}
class CompilerError extends Diagnostics {
CompilerError() { this.getSeverity() = "error" }
}
class CompilerWarning extends Diagnostics {
CompilerWarning() { this.getSeverity() = "warning" }
}
class CompilerNote extends Diagnostics {
CompilerNote() { this.getSeverity() = "note" }
}
class CompilerRemark extends Diagnostics {
CompilerRemark() { this.getSeverity() = "remark" }
}

View File

@@ -0,0 +1,11 @@
/**
* @name Compiler errors
* @description List all compiler errors for files in the source code directory.
* @kind diagnostic
* @id swift/diagnostics/compiler-errors
*/
import swift
from CompilerError error
select error, "Compiler error in " + error.getFile() + " with error message " + error.getText()

View File

@@ -1,3 +1,3 @@
| diags.swift:1:10:1:10 | Hello, warning | getText: | Hello, warning | getKind: | 2 |
| error.swift:2:14:2:14 | cannot convert value of type 'String' to specified type 'Int' | getText: | cannot convert value of type 'String' to specified type 'Int' | getKind: | 1 |
| import-error.swift:2:8:2:8 | no such module 'FooBar' | getText: | no such module 'FooBar' | getKind: | 1 |
| diags.swift:1:10:1:10 | warning: Hello, warning | getText: | Hello, warning | getKind: | 2 |
| error.swift:2:14:2:14 | error: cannot convert value of type 'String' to specified type 'Int' | getText: | cannot convert value of type 'String' to specified type 'Int' | getKind: | 1 |
| import-error.swift:2:8:2:8 | error: no such module 'FooBar' | getText: | no such module 'FooBar' | getKind: | 1 |