Skip to content

Commit 4cb4073

Browse files
QL: Add query to find non US spelling
1 parent dd6abdc commit 4cb4073

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

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)