Skip to content

Commit 98c5b81

Browse files
authored
Merge pull request github#11723 from aibaars/alert-suppression
CodeQL alert suppression
2 parents 4480262 + 035ad65 commit 98c5b81

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+609
-48
lines changed

cpp/ql/src/AlertSuppression.ql

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,18 @@
55
* @id cpp/alert-suppression
66
*/
77

8-
private import codeql.suppression.AlertSuppression as AS
8+
private import codeql.util.suppression.AlertSuppression as AS
99
private import semmle.code.cpp.Element
1010

11-
class SingleLineComment extends Comment {
11+
class AstNode extends Locatable {
12+
predicate hasLocationInfo(
13+
string filepath, int startline, int startcolumn, int endline, int endcolumn
14+
) {
15+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
16+
}
17+
}
18+
19+
class SingleLineComment extends Comment, AstNode {
1220
private string text;
1321

1422
SingleLineComment() {
@@ -26,14 +34,8 @@ class SingleLineComment extends Comment {
2634
not text.matches("%\n%")
2735
}
2836

29-
predicate hasLocationInfo(
30-
string filepath, int startline, int startcolumn, int endline, int endcolumn
31-
) {
32-
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
33-
}
34-
3537
/** Gets the text in this comment, excluding the leading //. */
3638
string getText() { result = text }
3739
}
3840

39-
import AS::Make<SingleLineComment>
41+
import AS::Make<AstNode, SingleLineComment>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `AlertSuppression.ql` query has been updated to support the new `// codeql[query-id]` supression comments. These comments can be used to suppress an alert and must be placed on a blank line before the alert. In addition the legacy `// lgtm` and `// lgtm[query-id]` comments can now also be place on the line before an alert.

cpp/ql/test/query-tests/AlertSuppression/AlertSuppression.expected

Lines changed: 64 additions & 0 deletions
Large diffs are not rendered by default.

cpp/ql/test/query-tests/AlertSuppression/tst.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ int x = 0; // lgtm
3434
3535
*/
3636
/* lgtm[@tag:nullness,js/invocation-of-non-function] */
37-
/* lgtm[@tag:nullness] */
37+
/* lgtm[@tag:nullness] */
38+
// codeql[js/debugger-statement]
39+
// CODEQL[js/debugger-statement]
40+
// codeql[js/debugger-statement] -- because I know better than codeql
41+
/* codeql[js/debugger-statement] */
42+
/* codeql[js/debugger-statement]
43+
*/
44+
int y; // codeql[js/debugger-statement]

cpp/ql/test/query-tests/AlertSuppression/tstWindows.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ int x = 0; // lgtm
3434
3535
*/
3636
/* lgtm[@tag:nullness,js/invocation-of-non-function] */
37-
/* lgtm[@tag:nullness] */
37+
/* lgtm[@tag:nullness] */
38+
// codeql[js/debugger-statement]
39+
// CODEQL[js/debugger-statement]
40+
// codeql[js/debugger-statement] -- because I know better than codeql
41+
/* codeql[js/debugger-statement] */
42+
/* codeql[js/debugger-statement]
43+
*/
44+
int y; // codeql[js/debugger-statement]

csharp/ql/src/AlertSuppression.ql

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@
55
* @id cs/alert-suppression
66
*/
77

8-
private import codeql.suppression.AlertSuppression as AS
8+
private import codeql.util.suppression.AlertSuppression as AS
99
private import semmle.code.csharp.Comments
1010

11+
class AstNode extends Element {
12+
predicate hasLocationInfo(
13+
string filepath, int startline, int startcolumn, int endline, int endcolumn
14+
) {
15+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
16+
}
17+
}
18+
1119
class SingleLineComment extends CommentLine {
1220
SingleLineComment() {
1321
// Must be either `// ...` or `/* ... */` on a single line.
@@ -21,4 +29,4 @@ class SingleLineComment extends CommentLine {
2129
}
2230
}
2331

24-
import AS::Make<SingleLineComment>
32+
import AS::Make<AstNode, SingleLineComment>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `AlertSuppression.ql` query has been updated to support the new `// codeql[query-id]` supression comments. These comments can be used to suppress an alert and must be placed on a blank line before the alert. In addition the legacy `// lgtm` and `// lgtm[query-id]` comments can now also be place on the line before an alert.

csharp/ql/test/query-tests/AlertSuppression/AlertSuppression.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,11 @@ class Dead { } // lgtm
2626
// LGTM[cs/unused-reftype]
2727
// lgtm[cs/unused-reftype] and lgtm[cs/unused-field]
2828
// lgtm[cs/unused-reftype]; lgtm
29+
// codeql[js/debugger-statement]
30+
// CODEQL[js/debugger-statement]
31+
// codeql[js/debugger-statement] -- because I know better than codeql
32+
/* codeql[js/debugger-statement] */
33+
/* codeql[js/debugger-statement]
34+
*/
35+
class End { } // codeql[js/debugger-statement]
36+

csharp/ql/test/query-tests/AlertSuppression/AlertSuppression.expected

Lines changed: 60 additions & 0 deletions
Large diffs are not rendered by default.

csharp/ql/test/query-tests/AlertSuppression/AlertSuppressionWindows.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@ class Dead2 { } // lgtm
3434
*/
3535
/* lgtm[@tag:nullness,cs/unused-reftype] */
3636
/* lgtm[@tag:nullness] */
37+
// codeql[js/debugger-statement]
38+
// CODEQL[js/debugger-statement]
39+
// codeql[js/debugger-statement] -- because I know better than codeql
40+
/* codeql[js/debugger-statement] */
41+
/* codeql[js/debugger-statement]
42+
*/
43+
class End2 { } // codeql[js/debugger-statement]
44+

0 commit comments

Comments
 (0)