mirror of
https://github.com/github/codeql.git
synced 2026-04-27 09:45:15 +02:00
Merge pull request #1353 from calumgrant/cs/diagnostic-queries3
C#: Add internal queries for extractor and compiler diagnostics
This commit is contained in:
11
csharp/ql/src/Diagnostics/CompilerError.qhelp
Normal file
11
csharp/ql/src/Diagnostics/CompilerError.qhelp
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE qhelp PUBLIC
|
||||
"-//Semmle//qhelp//EN"
|
||||
"qhelp.dtd">
|
||||
<qhelp>
|
||||
|
||||
<overview>
|
||||
<p>
|
||||
This is an internal query that finds all compilation errors reported by the C# compiler used by the C# extractor.</p>
|
||||
</overview>
|
||||
|
||||
</qhelp>
|
||||
16
csharp/ql/src/Diagnostics/CompilerError.ql
Normal file
16
csharp/ql/src/Diagnostics/CompilerError.ql
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* @name Compilation error
|
||||
* @description A compilation error can cause extraction problems, and could lead to inaccurate results.
|
||||
* @kind problem
|
||||
* @problem.severity recommendation
|
||||
* @precision high
|
||||
* @id cs/compilation-error
|
||||
* @tags internal non-attributable
|
||||
*/
|
||||
|
||||
import csharp
|
||||
import semmle.code.csharp.commons.Diagnostics
|
||||
|
||||
from CompilerError diagnostic
|
||||
select diagnostic,
|
||||
diagnostic.getSeverityText() + " " + diagnostic.getTag() + " " + diagnostic.getFullMessage()
|
||||
13
csharp/ql/src/Diagnostics/CompilerMessage.qhelp
Normal file
13
csharp/ql/src/Diagnostics/CompilerMessage.qhelp
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE qhelp PUBLIC
|
||||
"-//Semmle//qhelp//EN"
|
||||
"qhelp.dtd">
|
||||
<qhelp>
|
||||
|
||||
<overview>
|
||||
<p>
|
||||
This is an internal query that finds all messages reported by the C# compiler used by the C# extractor. This may include both compiler errors and
|
||||
compiler warnings.
|
||||
</p>
|
||||
</overview>
|
||||
|
||||
</qhelp>
|
||||
16
csharp/ql/src/Diagnostics/CompilerMessage.ql
Normal file
16
csharp/ql/src/Diagnostics/CompilerMessage.ql
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* @name Compilation message
|
||||
* @description A message emitted by the compiler, including warnings and errors.
|
||||
* @kind problem
|
||||
* @problem.severity recommendation
|
||||
* @precision high
|
||||
* @id cs/compilation-message
|
||||
* @tags internal non-attributable
|
||||
*/
|
||||
|
||||
import csharp
|
||||
import semmle.code.csharp.commons.Diagnostics
|
||||
|
||||
from Diagnostic diagnostic
|
||||
select diagnostic,
|
||||
diagnostic.getSeverityText() + " " + diagnostic.getTag() + " " + diagnostic.getFullMessage()
|
||||
22
csharp/ql/src/Diagnostics/ExtractorError.qhelp
Normal file
22
csharp/ql/src/Diagnostics/ExtractorError.qhelp
Normal file
@@ -0,0 +1,22 @@
|
||||
<!DOCTYPE qhelp PUBLIC
|
||||
"-//Semmle//qhelp//EN"
|
||||
"qhelp.dtd">
|
||||
<qhelp>
|
||||
|
||||
<overview>
|
||||
<p>
|
||||
This is an internal query that finds all errors reported by the C# extractor. It excludes results from files containing
|
||||
compilation errors, because these errors are likely to be caused by the compilation error rather than due to an internal
|
||||
error in the extractor.
|
||||
</p>
|
||||
|
||||
<p>Extractor errors can lead to inaccurate results.</p>
|
||||
</overview>
|
||||
|
||||
<recommendation>
|
||||
<p>
|
||||
Report extractor errors to Semmle.
|
||||
</p>
|
||||
</recommendation>
|
||||
|
||||
</qhelp>
|
||||
20
csharp/ql/src/Diagnostics/ExtractorError.ql
Normal file
20
csharp/ql/src/Diagnostics/ExtractorError.ql
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* @name Extraction error
|
||||
* @description An error message reported by the extractor, limited to those files where there are no
|
||||
* compilation errors. This indicates a bug or limitation in the extractor, and could lead
|
||||
* to inaccurate results.
|
||||
* @kind problem
|
||||
* @problem.severity recommendation
|
||||
* @precision high
|
||||
* @id cs/extraction-error
|
||||
* @tags internal non-attributable
|
||||
*/
|
||||
|
||||
import csharp
|
||||
import semmle.code.csharp.commons.Diagnostics
|
||||
|
||||
from ExtractorError error
|
||||
where not exists(CompilerError ce | ce.getLocation().getFile() = error.getLocation().getFile())
|
||||
select error,
|
||||
"Unexpected " + error.getOrigin() + " error in element '" + error.getElementText() +
|
||||
"' at location " + error.getStackTrace()
|
||||
16
csharp/ql/src/Diagnostics/ExtractorMessage.qhelp
Normal file
16
csharp/ql/src/Diagnostics/ExtractorMessage.qhelp
Normal file
@@ -0,0 +1,16 @@
|
||||
<!DOCTYPE qhelp PUBLIC
|
||||
"-//Semmle//qhelp//EN"
|
||||
"qhelp.dtd">
|
||||
<qhelp>
|
||||
|
||||
<overview>
|
||||
<p>
|
||||
This is an internal query that finds all messages reported by the extractor. These results may include extraction errors
|
||||
that are caused by compilation errors.
|
||||
</p>
|
||||
<p>
|
||||
Extractor errors can lead to inaccurate results.
|
||||
</p>
|
||||
</overview>
|
||||
|
||||
</qhelp>
|
||||
17
csharp/ql/src/Diagnostics/ExtractorMessage.ql
Normal file
17
csharp/ql/src/Diagnostics/ExtractorMessage.ql
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* @name Extraction message
|
||||
* @description An error message reported by the extractor. This could lead to inaccurate results.
|
||||
* @kind problem
|
||||
* @problem.severity recommendation
|
||||
* @precision high
|
||||
* @id cs/extraction-message
|
||||
* @tags internal non-attributable
|
||||
*/
|
||||
|
||||
import csharp
|
||||
import semmle.code.csharp.commons.Diagnostics
|
||||
|
||||
from ExtractorMessage message
|
||||
select message,
|
||||
message.getSeverityText() + " was generated by " + message.getOrigin() + " in element '" +
|
||||
message.getElementText() + "' at location " + message.getStackTrace()
|
||||
@@ -29,6 +29,17 @@ class Diagnostic extends @diagnostic {
|
||||
*/
|
||||
int getSeverity() { result = severity }
|
||||
|
||||
/** Gets a string representation of the severity of this diagnostic. */
|
||||
string getSeverityText() {
|
||||
severity = 0 and result = "Hidden"
|
||||
or
|
||||
severity = 1 and result = "Info"
|
||||
or
|
||||
severity = 2 and result = "Warning"
|
||||
or
|
||||
severity = 3 and result = "Error"
|
||||
}
|
||||
|
||||
/** Gets the identifier of this diagnostic, for example "CS8019". */
|
||||
string getTag() { result = tag }
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Diagnostics/CompilerError.ql
|
||||
@@ -0,0 +1,3 @@
|
||||
| Program.cs:7:13:7:13 | CS0219: The variable 'x' is assigned but its value is never used | Warning CS0219 The variable 'x' is assigned but its value is never used |
|
||||
| Program.cs:9:9:9:11 | CS0162: Unreachable code detected | Warning CS0162 Unreachable code detected |
|
||||
| Program.cs:9:13:9:13 | CS0219: The variable 'y' is assigned but its value is never used | Warning CS0219 The variable 'y' is assigned but its value is never used |
|
||||
@@ -0,0 +1 @@
|
||||
Diagnostics/CompilerMessage.ql
|
||||
@@ -0,0 +1 @@
|
||||
Diagnostics/ExtractorError.ql
|
||||
@@ -0,0 +1 @@
|
||||
Diagnostics/ExtractorMessage.ql
|
||||
Reference in New Issue
Block a user