Skip to content

Commit b0e8085

Browse files
committed
Go: use shared AlertSuppression.qll
1 parent 23f595b commit b0e8085

File tree

2 files changed

+7
-65
lines changed

2 files changed

+7
-65
lines changed

go/ql/src/AlertSuppression.ql

Lines changed: 6 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,14 @@
55
* @id go/alert-suppression
66
*/
77

8-
import go
8+
private import codeql.suppression.AlertSuppression as AS
9+
private import semmle.go.Comments as G
910

10-
/**
11-
* An alert suppression comment.
12-
*/
13-
class SuppressionComment extends Locatable {
14-
string text;
15-
string annotation;
16-
17-
SuppressionComment() {
18-
text = this.(Comment).getText() and
11+
class SingleLineComment extends G::Comment {
12+
SingleLineComment() {
1913
// suppression comments must be single-line
20-
not text.matches("%\n%") and
21-
(
22-
// match `lgtm[...]` anywhere in the comment
23-
annotation = text.regexpFind("(?i)\\blgtm\\s*\\[[^\\]]*\\]", _, _)
24-
or
25-
// match `lgtm` at the start of the comment and after semicolon
26-
annotation = text.regexpFind("(?i)(?<=^|;)\\s*lgtm(?!\\B|\\s*\\[)", _, _).trim()
27-
)
28-
}
29-
30-
/** Gets the text of this suppression comment, not including delimiters. */
31-
string getText() { result = text }
32-
33-
/** Gets the suppression annotation in this comment. */
34-
string getAnnotation() { result = annotation }
35-
36-
/**
37-
* Holds if this comment applies to the range from column `startcolumn` of line `startline`
38-
* to column `endcolumn` of line `endline` in file `filepath`.
39-
*/
40-
predicate covers(string filepath, int startline, int startcolumn, int endline, int endcolumn) {
41-
this.getLocation().hasLocationInfo(filepath, startline, _, endline, endcolumn) and
42-
startcolumn = 1
14+
not this.getText().matches("%\n%")
4315
}
44-
45-
/** Gets the scope of this suppression. */
46-
SuppressionScope getScope() { this = result.getSuppressionComment() }
47-
}
48-
49-
/**
50-
* The scope of an alert suppression comment.
51-
*/
52-
class SuppressionScope extends @locatable instanceof SuppressionComment {
53-
/** Gets a suppression comment with this scope. */
54-
SuppressionComment getSuppressionComment() { result = this }
55-
56-
/**
57-
* Holds if this element is at the specified location.
58-
* The location spans column `startcolumn` of line `startline` to
59-
* column `endcolumn` of line `endline` in file `filepath`.
60-
* For more information, see
61-
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
62-
*/
63-
predicate hasLocationInfo(
64-
string filepath, int startline, int startcolumn, int endline, int endcolumn
65-
) {
66-
super.covers(filepath, startline, startcolumn, endline, endcolumn)
67-
}
68-
69-
/** Gets a textual representation of this element. */
70-
string toString() { result = "suppression range" }
7116
}
7217

73-
from SuppressionComment c
74-
select c, // suppression comment
75-
c.getText(), // text of suppression comment (excluding delimiters)
76-
c.getAnnotation(), // text of suppression annotation
77-
c.getScope() // scope of suppression
18+
import AS::Make<SingleLineComment>

go/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/go-code-scanning.qls
99
dependencies:
1010
codeql/go-all: ${workspace}
1111
codeql/suite-helpers: ${workspace}
12+
codeql/util: ${workspace}

0 commit comments

Comments
 (0)