Skip to content

Commit 23f595b

Browse files
committed
JavaScript: use shared AlertSuppression.qll
1 parent bc646d4 commit 23f595b

File tree

2 files changed

+12
-59
lines changed

2 files changed

+12
-59
lines changed

javascript/ql/src/AlertSuppression.ql

Lines changed: 11 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,76 +5,28 @@
55
* @id js/alert-suppression
66
*/
77

8-
import javascript
8+
private import codeql.suppression.AlertSuppression as AS
9+
private import semmle.javascript.Locations as L
910

10-
/**
11-
* An alert suppression comment.
12-
*/
13-
class SuppressionComment extends Locatable {
14-
string text;
15-
string annotation;
11+
class SingleLineComment extends L::Locatable {
12+
private string text;
1613

17-
SuppressionComment() {
14+
SingleLineComment() {
1815
(
19-
text = this.(Comment).getText() or
20-
text = this.(HTML::CommentNode).getText()
16+
text = this.(L::Comment).getText() or
17+
text = this.(L::HTML::CommentNode).getText()
2118
) and
2219
// suppression comments must be single-line
23-
not text.matches("%\n%") and
24-
(
25-
// match `lgtm[...]` anywhere in the comment
26-
annotation = text.regexpFind("(?i)\\blgtm\\s*\\[[^\\]]*\\]", _, _)
27-
or
28-
// match `lgtm` at the start of the comment and after semicolon
29-
annotation = text.regexpFind("(?i)(?<=^|;)\\s*lgtm(?!\\B|\\s*\\[)", _, _).trim()
30-
)
31-
}
32-
33-
/** Gets the text of this suppression comment, not including delimiters. */
34-
string getText() { result = text }
35-
36-
/** Gets the suppression annotation in this comment. */
37-
string getAnnotation() { result = annotation }
38-
39-
/**
40-
* Holds if this comment applies to the range from column `startcolumn` of line `startline`
41-
* to column `endcolumn` of line `endline` in file `filepath`.
42-
*/
43-
predicate covers(string filepath, int startline, int startcolumn, int endline, int endcolumn) {
44-
this.getLocation().hasLocationInfo(filepath, startline, _, endline, endcolumn) and
45-
startcolumn = 1
20+
not text.matches("%\n%")
4621
}
4722

48-
/** Gets the scope of this suppression. */
49-
SuppressionScope getScope() { this = result.getSuppressionComment() }
50-
}
51-
52-
/**
53-
* The scope of an alert suppression comment.
54-
*/
55-
class SuppressionScope extends @locatable instanceof SuppressionComment {
56-
/** Gets a suppression comment with this scope. */
57-
SuppressionComment getSuppressionComment() { result = this }
58-
59-
/**
60-
* Holds if this element is at the specified location.
61-
* The location spans column `startcolumn` of line `startline` to
62-
* column `endcolumn` of line `endline` in file `filepath`.
63-
* For more information, see
64-
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
65-
*/
6623
predicate hasLocationInfo(
6724
string filepath, int startline, int startcolumn, int endline, int endcolumn
6825
) {
69-
super.covers(filepath, startline, startcolumn, endline, endcolumn)
26+
this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
7027
}
7128

72-
/** Gets a textual representation of this element. */
73-
string toString() { result = "suppression range" }
29+
string getText() { result = text }
7430
}
7531

76-
from SuppressionComment c
77-
select c, // suppression comment
78-
c.getText(), // text of suppression comment (excluding delimiters)
79-
c.getAnnotation(), // text of suppression annotation
80-
c.getScope() // scope of suppression
32+
import AS::Make<SingleLineComment>

javascript/ql/src/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ dependencies:
1010
codeql/javascript-all: ${workspace}
1111
codeql/suite-helpers: ${workspace}
1212
codeql/typos: ${workspace}
13+
codeql/util: ${workspace}

0 commit comments

Comments
 (0)