Skip to content

Commit f71359c

Browse files
committed
QL: detect toplevel block-comments that should be QLDoc
1 parent de08226 commit f71359c

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

ql/ql/src/queries/style/NonDocBlock.ql

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,43 @@ int getLineAboveNodeThatCouldHaveDoc(File file) {
3030
pragma[noinline]
3131
BlockComment getACommentThatCouldBeQLDoc(File file) {
3232
file = result.getLocation().getFile() and
33-
result.getLocation().getEndLine() = getLineAboveNodeThatCouldHaveDoc(file) and
3433
result.getLocation().getFile().getExtension() = "qll" and
35-
not result.getContents().matches("/**%")
34+
not result.getContents().matches("/**%") and
35+
(
36+
// above something that can be commented.
37+
result.getLocation().getEndLine() = getLineAboveNodeThatCouldHaveDoc(file)
38+
or
39+
// toplevel in file.
40+
result.getLocation().getStartLine() = 1 and
41+
result.getLocation().getStartColumn() = 1
42+
)
3643
}
3744

3845
pragma[noinline]
39-
BlockComment getCommentAt(File file, int endLine) {
46+
BlockComment getCommentAtEnd(File file, int endLine) {
4047
result = getACommentThatCouldBeQLDoc(file) and
4148
result.getLocation().getEndLine() = endLine
4249
}
4350

44-
from AstNode node, BlockComment comment
51+
pragma[noinline]
52+
BlockComment getCommentAtStart(File file, int startLine) {
53+
result = getACommentThatCouldBeQLDoc(file) and
54+
result.getLocation().getStartLine() = startLine
55+
}
56+
57+
from AstNode node, BlockComment comment, string nodeDescrip
4558
where
46-
canHaveQLDoc(node) and
59+
(
60+
canHaveQLDoc(node) and
61+
comment = getCommentAtEnd(node.getLocation().getFile(), node.getLocation().getStartLine() - 1) and
62+
nodeDescrip = "the below code"
63+
or
64+
node instanceof TopLevel and
65+
comment = getCommentAtStart(node.getLocation().getFile(), 1) and
66+
nodeDescrip = "the file"
67+
) and
4768
not exists(node.getQLDoc()) and
4869
not node.(ClassPredicate).isOverride() and // ignore override predicates
4970
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"
71+
not node.hasAnnotation("private") // ignore private
72+
select comment, "Block comment could be QLDoc for $@.", node, nodeDescrip

0 commit comments

Comments
 (0)