Skip to content

Commit 78caab4

Browse files
authored
Merge pull request github#81 from github/doc-style
Add some queries for qldoc style
2 parents 9a15fea + b4a0580 commit 78caab4

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @name Class QLDoc style.
3+
* @description The QLDoc for a class should start with "A", "An", or "The".
4+
* @kind problem
5+
* @problem.severity warning
6+
* @id ql/class-doc-style
7+
* @tags maintainability
8+
* @precision very-high
9+
*/
10+
11+
import ql
12+
13+
bindingset[s]
14+
predicate badStyle(string s) {
15+
not s.replaceAll("/**", "")
16+
.replaceAll("*", "")
17+
.splitAt("\n")
18+
.trim()
19+
.matches(["A %", "An %", "The %", "INTERNAL%", "DEPRECATED%"])
20+
}
21+
22+
from Class c
23+
where
24+
badStyle(c.getQLDoc().getContents()) and
25+
not c.isPrivate()
26+
select c.getQLDoc(), "The QLDoc for a class should start with 'A', 'An', or 'The'."
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @name Non US spelling
3+
* @description QLDocs shold use US spelling.
4+
* @kind problem
5+
* @problem.severity warning
6+
* @id ql/non-us-spelling
7+
* @tags maintainability
8+
* @precision very-high
9+
*/
10+
11+
import ql
12+
13+
predicate non_us_word(string wrong, string right) {
14+
exists(string s |
15+
wrong = s.splitAt("/", 0) and
16+
right = s.splitAt("/", 1) and
17+
s = ["colour/color", "authorise/authorize", "analyse/analyze"]
18+
)
19+
}
20+
21+
bindingset[s]
22+
predicate contains_non_us_spelling(string s, string wrong, string right) {
23+
non_us_word(wrong, right) and
24+
(
25+
s.matches("%" + wrong + "%") and
26+
wrong != "analyse"
27+
or
28+
// analyses (as a noun) is fine
29+
s.regexpMatch(".*analyse[^s].*") and
30+
wrong = "analyse"
31+
)
32+
}
33+
34+
from QLDoc doc, string wrong, string right
35+
where contains_non_us_spelling(doc.getContents().toLowerCase(), wrong, right)
36+
select doc,
37+
"This QLDoc comment contains the non-US spelling '" + wrong + "', which should instead be '" +
38+
right + "'."

0 commit comments

Comments
 (0)