Skip to content

Commit c176606

Browse files
committed
AlertSuppression: allow //lgtm comments to scope over the next line
1 parent 016c7a8 commit c176606

File tree

14 files changed

+345
-28
lines changed

14 files changed

+345
-28
lines changed

cpp/ql/src/AlertSuppression.ql

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@
88
private import codeql.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>

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

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

csharp/ql/src/AlertSuppression.ql

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
private import codeql.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>

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

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

go/ql/src/AlertSuppression.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ class SingleLineComment extends G::Comment {
1515
}
1616
}
1717

18-
import AS::Make<SingleLineComment>
18+
import AS::Make<G::Locatable, SingleLineComment>

java/ql/src/AlertSuppression.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ class SingleLineComment extends Javadoc {
1818
string getText() { result = this.getChild(0).getText() }
1919
}
2020

21-
import AS::Make<SingleLineComment>
21+
import AS::Make<Top, SingleLineComment>

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

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

javascript/ql/src/AlertSuppression.ql

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@
88
private import codeql.suppression.AlertSuppression as AS
99
private import javascript as JS
1010

11-
class SingleLineComment extends JS::Locatable {
11+
class AstNode extends JS::Locatable {
12+
AstNode() { not this.(JS::HTML::TextNode).getText().regexpMatch("\\s*") }
13+
14+
predicate hasLocationInfo(
15+
string filepath, int startline, int startcolumn, int endline, int endcolumn
16+
) {
17+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
18+
}
19+
}
20+
21+
class SingleLineComment extends AstNode {
1222
private string text;
1323

1424
SingleLineComment() {
@@ -20,13 +30,7 @@ class SingleLineComment extends JS::Locatable {
2030
not text.matches("%\n%")
2131
}
2232

23-
predicate hasLocationInfo(
24-
string filepath, int startline, int startcolumn, int endline, int endcolumn
25-
) {
26-
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
27-
}
28-
2933
string getText() { result = text }
3034
}
3135

32-
import AS::Make<SingleLineComment>
36+
import AS::Make<AstNode, SingleLineComment>

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

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

python/ql/src/AlertSuppression.ql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
private import codeql.suppression.AlertSuppression as AS
99
private import semmle.python.Comment as P
1010

11+
class AstNode instanceof P::AstNode {
12+
predicate hasLocationInfo(
13+
string filepath, int startline, int startcolumn, int endline, int endcolumn
14+
) {
15+
super.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
16+
}
17+
18+
string toString() { result = super.toString() }
19+
}
20+
1121
class SingleLineComment instanceof P::Comment {
1222
predicate hasLocationInfo(
1323
string filepath, int startline, int startcolumn, int endline, int endcolumn
@@ -20,7 +30,7 @@ class SingleLineComment instanceof P::Comment {
2030
string toString() { result = super.toString() }
2131
}
2232

23-
import AS::Make<SingleLineComment>
33+
import AS::Make<AstNode, SingleLineComment>
2434

2535
/**
2636
* A noqa suppression comment. Both pylint and pyflakes respect this, so lgtm ought to too.

0 commit comments

Comments
 (0)