Skip to content

Commit 453045e

Browse files
committed
C#: use shared AlertSuppression.qll
1 parent ad80822 commit 453045e

File tree

2 files changed

+8
-55
lines changed

2 files changed

+8
-55
lines changed

csharp/ql/src/AlertSuppression.ql

Lines changed: 7 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,68 +5,20 @@
55
* @id cs/alert-suppression
66
*/
77

8-
import csharp
8+
private import codeql.suppression.AlertSuppression as AS
9+
private import semmle.code.csharp.Comments
910

10-
/**
11-
* An alert suppression comment.
12-
*/
13-
class SuppressionComment extends CommentLine {
14-
string annotation;
15-
16-
SuppressionComment() {
11+
class SingleLineComment extends CommentLine {
12+
SingleLineComment() {
1713
// Must be either `// ...` or `/* ... */` on a single line.
18-
this.getRawText().regexpMatch("//.*|/\\*.*\\*/") and
19-
exists(string text | text = this.getText() |
20-
// match `lgtm[...]` anywhere in the comment
21-
annotation = text.regexpFind("(?i)\\blgtm\\s*\\[[^\\]]*\\]", _, _)
22-
or
23-
// match `lgtm` at the start of the comment and after semicolon
24-
annotation = text.regexpFind("(?i)(?<=^|;)\\s*lgtm(?!\\B|\\s*\\[)", _, _).trim()
25-
)
26-
}
27-
28-
/** Gets the suppression annotation in this comment. */
29-
string getAnnotation() { result = annotation }
30-
31-
/**
32-
* Holds if this comment applies to the range from column `startcolumn` of line `startline`
33-
* to column `endcolumn` of line `endline` in file `filepath`.
34-
*/
35-
predicate covers(string filepath, int startline, int startcolumn, int endline, int endcolumn) {
36-
this.getLocation().hasLocationInfo(filepath, startline, _, endline, endcolumn) and
37-
startcolumn = 1
14+
this.getRawText().regexpMatch("//.*|/\\*.*\\*/")
3815
}
3916

40-
/** Gets the scope of this suppression. */
41-
SuppressionScope getScope() { this = result.getSuppressionComment() }
42-
}
43-
44-
/**
45-
* The scope of an alert suppression comment.
46-
*/
47-
class SuppressionScope extends @commentline instanceof SuppressionComment {
48-
/** Gets a suppression comment with this scope. */
49-
SuppressionComment getSuppressionComment() { result = this }
50-
51-
/**
52-
* Holds if this element is at the specified location.
53-
* The location spans column `startcolumn` of line `startline` to
54-
* column `endcolumn` of line `endline` in file `filepath`.
55-
* For more information, see
56-
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
57-
*/
5817
predicate hasLocationInfo(
5918
string filepath, int startline, int startcolumn, int endline, int endcolumn
6019
) {
61-
super.covers(filepath, startline, startcolumn, endline, endcolumn)
20+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
6221
}
63-
64-
/** Gets a textual representation of this element. */
65-
string toString() { result = "suppression range" }
6622
}
6723

68-
from SuppressionComment c
69-
select c, // suppression comment
70-
c.getText(), // text of suppression comment (excluding delimiters)
71-
c.getAnnotation(), // text of suppression annotation
72-
c.getScope() // scope of suppression
24+
import AS::Make<SingleLineComment>

csharp/ql/src/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ defaultSuiteFile: codeql-suites/csharp-code-scanning.qls
99
dependencies:
1010
codeql/csharp-all: ${workspace}
1111
codeql/suite-helpers: ${workspace}
12+
codeql/util: ${workspace}

0 commit comments

Comments
 (0)