|
5 | 5 | * @id java/alert-suppression
|
6 | 6 | */
|
7 | 7 |
|
8 |
| -import java |
9 |
| - |
10 |
| -/** |
11 |
| - * An alert suppression comment. |
12 |
| - */ |
13 |
| -class SuppressionComment extends Javadoc { |
14 |
| - string annotation; |
15 |
| - |
16 |
| - SuppressionComment() { |
17 |
| - // suppression comments must be single-line |
18 |
| - ( |
19 |
| - isEolComment(this) |
20 |
| - or |
21 |
| - isNormalComment(this) and exists(int line | this.hasLocationInfo(_, line, _, line, _)) |
22 |
| - ) and |
23 |
| - exists(string text | text = this.getChild(0).getText() | |
24 |
| - // match `lgtm[...]` anywhere in the comment |
25 |
| - annotation = text.regexpFind("(?i)\\blgtm\\s*\\[[^\\]]*\\]", _, _) |
26 |
| - or |
27 |
| - // match `lgtm` at the start of the comment and after semicolon |
28 |
| - annotation = text.regexpFind("(?i)(?<=^|;)\\s*lgtm(?!\\B|\\s*\\[)", _, _).trim() |
29 |
| - ) |
| 8 | +private import codeql.suppression.AlertSuppression as AS |
| 9 | +private import semmle.code.java.Javadoc |
| 10 | + |
| 11 | +class SingleLineComment extends Javadoc { |
| 12 | + SingleLineComment() { |
| 13 | + isEolComment(this) |
| 14 | + or |
| 15 | + isNormalComment(this) and exists(int line | this.hasLocationInfo(_, line, _, line, _)) |
30 | 16 | }
|
31 | 17 |
|
32 |
| - /** |
33 |
| - * Gets the text of this suppression comment. |
34 |
| - */ |
35 | 18 | string getText() { result = this.getChild(0).getText() }
|
36 |
| - |
37 |
| - /** Gets the suppression annotation in this comment. */ |
38 |
| - string getAnnotation() { result = annotation } |
39 |
| - |
40 |
| - /** |
41 |
| - * Holds if this comment applies to the range from column `startcolumn` of line `startline` |
42 |
| - * to column `endcolumn` of line `endline` in file `filepath`. |
43 |
| - */ |
44 |
| - predicate covers(string filepath, int startline, int startcolumn, int endline, int endcolumn) { |
45 |
| - this.getLocation().hasLocationInfo(filepath, startline, _, endline, endcolumn) and |
46 |
| - startcolumn = 1 |
47 |
| - } |
48 |
| - |
49 |
| - /** Gets the scope of this suppression. */ |
50 |
| - SuppressionScope getScope() { this = result.getSuppressionComment() } |
51 |
| -} |
52 |
| - |
53 |
| -/** |
54 |
| - * The scope of an alert suppression comment. |
55 |
| - */ |
56 |
| -class SuppressionScope extends @javadoc instanceof SuppressionComment { |
57 |
| - /** Gets a suppression comment with this scope. */ |
58 |
| - SuppressionComment getSuppressionComment() { result = this } |
59 |
| - |
60 |
| - /** |
61 |
| - * Holds if this element is at the specified location. |
62 |
| - * The location spans column `startcolumn` of line `startline` to |
63 |
| - * column `endcolumn` of line `endline` in file `filepath`. |
64 |
| - * For more information, see |
65 |
| - * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). |
66 |
| - */ |
67 |
| - predicate hasLocationInfo( |
68 |
| - string filepath, int startline, int startcolumn, int endline, int endcolumn |
69 |
| - ) { |
70 |
| - super.covers(filepath, startline, startcolumn, endline, endcolumn) |
71 |
| - } |
72 |
| - |
73 |
| - /** Gets a textual representation of this element. */ |
74 |
| - string toString() { result = "suppression range" } |
75 | 19 | }
|
76 | 20 |
|
77 |
| -from SuppressionComment c |
78 |
| -select c, // suppression comment |
79 |
| - c.getText(), // text of suppression comment (excluding delimiters) |
80 |
| - c.getAnnotation(), // text of suppression annotation |
81 |
| - c.getScope() // scope of suppression |
| 21 | +import AS::Make<SingleLineComment> |
0 commit comments