QL: move ql/non-us-spelling implementation to Query.qll file

This commit is contained in:
Erik Krogh Kristensen
2021-12-20 16:53:52 +01:00
parent d17879e1f9
commit 66c6a4d899
2 changed files with 25 additions and 25 deletions

View File

@@ -0,0 +1,24 @@
predicate non_us_word(string wrong, string right) {
exists(string s |
wrong = s.splitAt("/", 0) and
right = s.splitAt("/", 1) and
s =
[
"colour/color", "authorise/authorize", "analyse/analyze", "behaviour/behavior",
"modelling/modeling"
]
)
}
bindingset[s]
predicate contains_non_us_spelling(string s, string wrong, string right) {
non_us_word(wrong, right) and
(
s.matches("%" + wrong + "%") and
wrong != "analyse"
or
// analyses (as a noun) is fine
s.regexpMatch(".*analyse[^s].*") and
wrong = "analyse"
)
}

View File

@@ -9,31 +9,7 @@
*/
import ql
predicate non_us_word(string wrong, string right) {
exists(string s |
wrong = s.splitAt("/", 0) and
right = s.splitAt("/", 1) and
s =
[
"colour/color", "authorise/authorize", "analyse/analyze", "behaviour/behavior",
"modelling/modeling"
]
)
}
bindingset[s]
predicate contains_non_us_spelling(string s, string wrong, string right) {
non_us_word(wrong, right) and
(
s.matches("%" + wrong + "%") and
wrong != "analyse"
or
// analyses (as a noun) is fine
s.regexpMatch(".*analyse[^s].*") and
wrong = "analyse"
)
}
import codeql_ql.style.docs.NonUSSpellingQuery
from QLDoc doc, string wrong, string right
where contains_non_us_spelling(doc.getContents().toLowerCase(), wrong, right)