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 {
178178 override string getAPrimaryQlClass ( ) { result = "BlockComment" }
179179}
180180
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+
181191/**
182192 * The `from, where, select` part of a QL query.
183193 */
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ newtype TAstNode =
77 TTopLevel ( QL:: Ql file ) or
88 TQLDoc ( QL:: Qldoc qldoc ) or
99 TBlockComment ( QL:: BlockComment comment ) or
10+ TLineComment ( QL:: LineComment comment ) or
1011 TClasslessPredicate ( QL:: ClasslessPredicate pred ) or
1112 TVarDecl ( QL:: VarDecl decl ) or
1213 TFieldDecl ( QL:: Field field ) or
@@ -154,6 +155,8 @@ QL::AstNode toQL(AST::AstNode n) {
154155 or
155156 n = TBlockComment ( result )
156157 or
158+ n = TLineComment ( result )
159+ or
157160 n = TClasslessPredicate ( result )
158161 or
159162 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