Skip to content

Commit 3762ce2

Browse files
committed
QL: also report missing QLDoc for parameters when no parameters are documented
1 parent f204a41 commit 3762ce2

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

ql/ql/src/queries/style/MissingParameterInQlDoc.ql

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,35 @@ private string getAMentionedNonParameter(Predicate p) {
4242
) and
4343
result.regexpMatch("^[a-z]\\w+$") and
4444
not result.toLowerCase() = getAParameterName(p).toLowerCase() and
45-
not result = ["true", "false", "NaN"] and // keywords
46-
not result.regexpMatch("\\d+") and // numbers
45+
not result = ["true", "false", "NaN", "this"] and // keywords
46+
not result = getMentionedPredicates(p.getLocation().getFile()) and
47+
// variables inside the predicate are also fine
48+
not result = any(VarDecl var | var.getEnclosingPredicate() = p).getName()
49+
}
50+
51+
/** Gets the names of all predicates that are mentioned in `file`. */
52+
pragma[noinline]
53+
private string getMentionedPredicates(File file) {
4754
// predicates get mentioned all the time, it's fine.
48-
not result =
49-
any(Predicate pred | pred.getLocation().getFile() = p.getLocation().getFile()).getName() and
50-
// classes get mentioned all the time, it's fine.
51-
not result =
52-
any(TypeExpr t | t.getLocation().getFile() = p.getLocation().getFile())
53-
.getResolvedType()
54-
.getName()
55+
result = any(Predicate pred | pred.getLocation().getFile() = file).getName() or
56+
result = any(Call c | c.getLocation().getFile() = file).getTarget().getName()
5557
}
5658

5759
/** Gets a parameter name from `p` that is not mentioned in the qldoc. */
5860
private string getAnUndocumentedParameter(Predicate p) {
5961
result = getAParameterName(p) and
6062
not result.toLowerCase() = getADocumentedParameter(p).toLowerCase() and
61-
not result = ["config", "conf", "cfg"] // DataFlow configurations are often undocumented, and that's fine.
62-
}
63-
64-
/** Holds if `p` has documented parameters, but `param` is undocumented */
65-
private predicate missingDocumentation(Predicate p, string param) {
66-
param = getAnUndocumentedParameter(p) and
67-
exists(getADocumentedParameter(p))
63+
not result = ["config", "conf", "cfg"] and // DataFlow configurations are often undocumented, and that's fine.
64+
not (
65+
// "the given" often refers to the first parameter.
66+
p.getQLDoc().getContents().regexpMatch("(?s).*\\bthe given\\b.*") and
67+
result = p.getParameter(0).getName()
68+
)
6869
}
6970

7071
/** Gets the one string containing the undocumented parameters from `p` */
7172
private string getUndocumentedParameters(Predicate p) {
72-
result = strictconcat(string param | missingDocumentation(p, param) | param, ", or ")
73+
result = strictconcat(string param | param = getAnUndocumentedParameter(p) | param, ", or ")
7374
}
7475

7576
/** Gets the parameter-like names mentioned in the QLDoc of `p` that are not parameters. */
@@ -78,6 +79,7 @@ private string getMentionedNonParameters(Predicate p) {
7879
}
7980

8081
from Predicate p
82+
where not p.getLocation().getFile().getBaseName() = "Aliases.qll" // these are OK
8183
select p,
8284
"The QLDoc has no documentation for " + getUndocumentedParameters(p) + ", but the QLDoc mentions "
8385
+ getMentionedNonParameters(p)

0 commit comments

Comments
 (0)