-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathNonDocBlock.ql
More file actions
87 lines (79 loc) · 2.5 KB
/
NonDocBlock.ql
File metadata and controls
87 lines (79 loc) · 2.5 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
/**
* @name Block comment that is not QLDoc
* @description Placing a block comment that could have been a QLDoc comment is an indication that it should have been a QLDoc comment.
* @kind problem
* @problem.severity warning
* @id ql/non-doc-block
* @tags maintainability
* @precision very-high
*/
import ql
predicate canHaveQLDoc(AstNode node) {
node instanceof Class
or
node instanceof Module
or
node instanceof ClasslessPredicate
or
node instanceof ClassPredicate
}
pragma[noinline]
int getLineAboveNodeThatCouldHaveDoc(File file) {
exists(AstNode node | canHaveQLDoc(node) |
result = node.getLocation().getStartLine() - 1 and file = node.getLocation().getFile()
)
}
pragma[noinline]
BlockComment getACommentThatCouldBeQLDoc(File file) {
exists(Location loc | loc = result.getLocation() |
file = loc.getFile() and
loc.getFile().getExtension() = "qll" and
not result.getContents().matches("/**%") and
not [loc.getStartLine(), loc.getEndLine()] = getLinesWithNonComment(file) and
(
// above something that can be commented.
loc.getEndLine() = getLineAboveNodeThatCouldHaveDoc(file)
or
// toplevel in file.
loc.getStartLine() = 1 and
loc.getStartColumn() = 1
)
)
}
pragma[noinline]
int getLinesWithNonComment(File f) {
exists(AstNode n, Location loc |
not n instanceof Comment and
not n instanceof TopLevel and
loc = n.getLocation() and
loc.getFile() = f
|
result = [loc.getEndLine(), loc.getStartLine()]
)
}
pragma[noinline]
BlockComment getCommentAtEnd(File file, int endLine) {
result = getACommentThatCouldBeQLDoc(file) and
result.getLocation().getEndLine() = endLine
}
pragma[noinline]
BlockComment getCommentAtStart(File file, int startLine) {
result = getACommentThatCouldBeQLDoc(file) and
result.getLocation().getStartLine() = startLine
}
from AstNode node, BlockComment comment, string nodeDescrip
where
(
canHaveQLDoc(node) and
comment = getCommentAtEnd(node.getLocation().getFile(), node.getLocation().getStartLine() - 1) and
nodeDescrip = "the below code"
or
node instanceof TopLevel and
comment = getCommentAtStart(node.getLocation().getFile(), 1) and
nodeDescrip = "the file"
) and
not exists(node.getQLDoc()) and
not node.(ClassPredicate).isOverride() and // ignore override predicates
not node.hasAnnotation("deprecated") and // ignore deprecated
not node.hasAnnotation("private") // ignore private
select comment, "Block comment could be QLDoc for $@.", node, nodeDescrip