|
5 | 5 | * @id js/alert-suppression |
6 | 6 | */ |
7 | 7 |
|
8 | | -import javascript |
| 8 | +private import codeql.suppression.AlertSuppression as AS |
| 9 | +private import semmle.javascript.Locations as L |
9 | 10 |
|
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; |
16 | 13 |
|
17 | | - SuppressionComment() { |
| 14 | + SingleLineComment() { |
18 | 15 | ( |
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() |
21 | 18 | ) and |
22 | 19 | // 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%") |
46 | 21 | } |
47 | 22 |
|
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 | | - */ |
66 | 23 | predicate hasLocationInfo( |
67 | 24 | string filepath, int startline, int startcolumn, int endline, int endcolumn |
68 | 25 | ) { |
69 | | - super.covers(filepath, startline, startcolumn, endline, endcolumn) |
| 26 | + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) |
70 | 27 | } |
71 | 28 |
|
72 | | - /** Gets a textual representation of this element. */ |
73 | | - string toString() { result = "suppression range" } |
| 29 | + string getText() { result = text } |
74 | 30 | } |
75 | 31 |
|
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> |
0 commit comments