mirror of
https://github.com/github/codeql.git
synced 2026-02-08 19:21:07 +01:00
Merge pull request #81 from github/doc-style
Add some queries for qldoc style
This commit is contained in:
26
ql/src/queries/style/docs/ClassDocs.ql
Normal file
26
ql/src/queries/style/docs/ClassDocs.ql
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* @name Class QLDoc style.
|
||||
* @description The QLDoc for a class should start with "A", "An", or "The".
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @id ql/class-doc-style
|
||||
* @tags maintainability
|
||||
* @precision very-high
|
||||
*/
|
||||
|
||||
import ql
|
||||
|
||||
bindingset[s]
|
||||
predicate badStyle(string s) {
|
||||
not s.replaceAll("/**", "")
|
||||
.replaceAll("*", "")
|
||||
.splitAt("\n")
|
||||
.trim()
|
||||
.matches(["A %", "An %", "The %", "INTERNAL%", "DEPRECATED%"])
|
||||
}
|
||||
|
||||
from Class c
|
||||
where
|
||||
badStyle(c.getQLDoc().getContents()) and
|
||||
not c.isPrivate()
|
||||
select c.getQLDoc(), "The QLDoc for a class should start with 'A', 'An', or 'The'."
|
||||
38
ql/src/queries/style/docs/NonUSSpelling.ql
Normal file
38
ql/src/queries/style/docs/NonUSSpelling.ql
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @name Non US spelling
|
||||
* @description QLDocs shold use US spelling.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @id ql/non-us-spelling
|
||||
* @tags maintainability
|
||||
* @precision very-high
|
||||
*/
|
||||
|
||||
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"]
|
||||
)
|
||||
}
|
||||
|
||||
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"
|
||||
)
|
||||
}
|
||||
|
||||
from QLDoc doc, string wrong, string right
|
||||
where contains_non_us_spelling(doc.getContents().toLowerCase(), wrong, right)
|
||||
select doc,
|
||||
"This QLDoc comment contains the non-US spelling '" + wrong + "', which should instead be '" +
|
||||
right + "'."
|
||||
Reference in New Issue
Block a user