forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComments.qll
More file actions
137 lines (120 loc) · 2.8 KB
/
Copy pathComments.qll
File metadata and controls
137 lines (120 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/** Provides classes for working with JavaScript comments. */
import javascript
/**
* A JavaScript source-code comment.
*
* Examples:
*
* <pre>
* // a line comment
* /* a block
* comment */
* <!-- an HTML line comment
* </pre>
*/
class Comment extends @comment, Locatable {
override Location getLocation() { hasLocation(this, result) }
/** Gets the toplevel element this comment belongs to. */
TopLevel getTopLevel() { comments(this, _, result, _, _) }
/** Gets the text of this comment, not including delimiters. */
string getText() { comments(this, _, _, result, _) }
/** Gets the `i`th line of comment text. */
string getLine(int i) { result = getText().splitAt("\n", i) }
/** Gets the next token after this comment. */
Token getNextToken() { next_token(this, result) }
override int getNumLines() { result = count(getLine(_)) }
override string toString() { comments(this, _, _, _, result) }
/** Holds if this comment spans lines `start` to `end` (inclusive) in file `f`. */
predicate onLines(File f, int start, int end) {
exists(Location loc | loc = getLocation() |
f = loc.getFile() and
start = loc.getStartLine() and
end = loc.getEndLine()
)
}
}
/**
* A line comment, that is, either an HTML comment or a `//` comment.
*
* Examples:
*
* <pre>
* // a line comment
* <!-- an HTML line comment
* </pre>
*/
class LineComment extends @line_comment, Comment { }
/**
* An HTML comment start/end token interpreted as a line comment.
*
* Example:
*
* ```
* <!-- an HTML line comment
* --> also an HTML line comment
* ```
*/
class HtmlLineComment extends @html_comment, LineComment { }
/**
* An HTML comment start token interpreted as a line comment.
*
* Example:
*
* ```
* <!-- an HTML line comment
* ```
*/
class HtmlCommentStart extends @html_comment_start, HtmlLineComment { }
/**
* An HTML comment end token interpreted as a line comment.
*
* Example:
*
* ```
* --> also an HTML line comment
* ```
*/
class HtmlCommentEnd extends @htmlcommentend, HtmlLineComment { }
/**
* A `//` comment.
*
* Example:
*
* ```
* // a line comment
* ```
*/
class SlashSlashComment extends @slashslash_comment, LineComment { }
/**
* A block comment (which may be a JSDoc comment).
*
* Examples:
*
* <pre>
* /* a block comment
* (but not a JSDoc comment) */
* /** a JSDoc comment */
* </pre>
*/
class BlockComment extends @block_comment, Comment { }
/**
* A C-style block comment which is not a JSDoc comment.
*
* Example:
*
* <pre>
* /* a block comment
* (but not a JSDoc comment) */
* </pre>
*/
class SlashStarComment extends @slashstar_comment, BlockComment { }
/**
* A JSDoc comment.
*
* Example:
*
* <pre>
* /** a JSDoc comment */
* </pre>
*/
class DocComment extends @doc_comment, BlockComment { }