File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -178,6 +178,16 @@ class BlockComment extends TBlockComment, AstNode {
178
178
override string getAPrimaryQlClass ( ) { result = "BlockComment" }
179
179
}
180
180
181
+ class LineComment extends TLineComment , AstNode {
182
+ QL:: LineComment comment ;
183
+
184
+ LineComment ( ) { this = TLineComment ( comment ) }
185
+
186
+ string getContents ( ) { result = comment .getValue ( ) }
187
+
188
+ override string getAPrimaryQlClass ( ) { result = "LineComment" }
189
+ }
190
+
181
191
/**
182
192
* The `from, where, select` part of a QL query.
183
193
*/
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ newtype TAstNode =
7
7
TTopLevel ( QL:: Ql file ) or
8
8
TQLDoc ( QL:: Qldoc qldoc ) or
9
9
TBlockComment ( QL:: BlockComment comment ) or
10
+ TLineComment ( QL:: LineComment comment ) or
10
11
TClasslessPredicate ( QL:: ClasslessPredicate pred ) or
11
12
TVarDecl ( QL:: VarDecl decl ) or
12
13
TFieldDecl ( QL:: Field field ) or
@@ -154,6 +155,8 @@ QL::AstNode toQL(AST::AstNode n) {
154
155
or
155
156
n = TBlockComment ( result )
156
157
or
158
+ n = TLineComment ( result )
159
+ or
157
160
n = TClasslessPredicate ( result )
158
161
or
159
162
n = TVarDecl ( result )
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @name Comment has repeated word
3
+ * @description Comment has repeated word.
4
+ * @kind problem
5
+ * @problem.severity warning
6
+ * @id ql/repeated-word
7
+ * @precision very-high
8
+ */
9
+
10
+ import ql
11
+
12
+ string getComment ( AstNode node ) {
13
+ result = node .( QLDoc ) .getContents ( )
14
+ or
15
+ result = node .( BlockComment ) .getContents ( )
16
+ or
17
+ result = node .( LineComment ) .getContents ( )
18
+ }
19
+
20
+ /** Gets a word used in `node` */
21
+ string getWord ( AstNode node ) { result = getComment ( node ) .regexpFind ( "\\b[A-Za-z]+\\b" , _, _) }
22
+
23
+ AstNode hasRepeatedWord ( string word ) {
24
+ word = getWord ( result ) and
25
+ getComment ( result ) .regexpMatch ( ".*\\b" + word + "\\s+" + word + "\\b.*" )
26
+ }
27
+
28
+ from AstNode comment , string word
29
+ where comment = hasRepeatedWord ( word )
30
+ select comment , "The comment repeats " + word + "."
You can’t perform that action at this time.
0 commit comments