|
| 1 | +/** |
| 2 | + * @name Block comment that is not QLDoc |
| 3 | + * @description Placing a block comment that could have been a QLDoc comment is an indication that it should have been a QLDoc comment. |
| 4 | + * @kind problem |
| 5 | + * @problem.severity warning |
| 6 | + * @id ql/non-doc-block |
| 7 | + * @tags maintainability |
| 8 | + * @precision very-high |
| 9 | + */ |
| 10 | + |
| 11 | +import ql |
| 12 | + |
| 13 | +predicate canHaveQLDoc(AstNode node) { |
| 14 | + node instanceof Class |
| 15 | + or |
| 16 | + node instanceof Module |
| 17 | + or |
| 18 | + node instanceof ClasslessPredicate |
| 19 | + or |
| 20 | + node instanceof ClassPredicate |
| 21 | +} |
| 22 | + |
| 23 | +pragma[noinline] |
| 24 | +int getLineAboveNodeThatCouldHaveDoc(File file) { |
| 25 | + exists(AstNode node | canHaveQLDoc(node) | |
| 26 | + result = node.getLocation().getStartLine() - 1 and file = node.getLocation().getFile() |
| 27 | + ) |
| 28 | +} |
| 29 | + |
| 30 | +pragma[noinline] |
| 31 | +BlockComment getACommentThatCouldBeQLDoc(File file) { |
| 32 | + file = result.getLocation().getFile() and |
| 33 | + result.getLocation().getEndLine() = getLineAboveNodeThatCouldHaveDoc(file) and |
| 34 | + result.getLocation().getFile().getExtension() = "qll" and |
| 35 | + not result.getContents().matches("/**%") |
| 36 | +} |
| 37 | + |
| 38 | +pragma[noinline] |
| 39 | +BlockComment getCommentAt(File file, int endLine) { |
| 40 | + result = getACommentThatCouldBeQLDoc(file) and |
| 41 | + result.getLocation().getEndLine() = endLine |
| 42 | +} |
| 43 | + |
| 44 | +from AstNode node, BlockComment comment |
| 45 | +where |
| 46 | + canHaveQLDoc(node) and |
| 47 | + not exists(node.getQLDoc()) and |
| 48 | + not node.(ClassPredicate).isOverride() and // ignore override predicates |
| 49 | + not node.hasAnnotation("deprecated") and // ignore deprecated |
| 50 | + not node.hasAnnotation("private") and // ignore private |
| 51 | + comment = getCommentAt(node.getLocation().getFile(), node.getLocation().getStartLine() - 1) |
| 52 | +select comment, "Block comment could be QLDoc for $@.", node, "the below code" |
0 commit comments