mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Ql4Ql: Address review comments.
This commit is contained in:
@@ -232,8 +232,8 @@ class QueryDoc extends QLDoc {
|
||||
result = this.getContents().regexpCapture("(?s).*@security\\-severity ([\\d\\.]+)\\s.*", 1)
|
||||
}
|
||||
|
||||
/** Gets the individual @tags for the query. */
|
||||
string getQueryTags() {
|
||||
/** Gets the individual @tags for the query, if any. */
|
||||
string getAQueryTag() {
|
||||
exists(string tags | tags = this.getContents().regexpCapture("(?s).*@tags ([^@]+)", 1) |
|
||||
result = tags.splitAt("*").trim() and
|
||||
result.regexpMatch("[\\w\\s\\-]+")
|
||||
|
||||
@@ -10,18 +10,18 @@
|
||||
|
||||
import ql
|
||||
|
||||
private predicate hasQualityTag(QueryDoc doc) { doc.getQueryTags() = "quality" }
|
||||
private predicate hasQualityTag(QueryDoc doc) { doc.getAQueryTag() = "quality" }
|
||||
|
||||
private predicate incorrectTopLevelCategorisation(QueryDoc doc) {
|
||||
count(string s | s = doc.getQueryTags() and s = ["maintainability", "reliability"]) != 1
|
||||
private predicate correctTopLevelCategorisation(QueryDoc doc) {
|
||||
strictcount(string s | s = doc.getAQueryTag() and s = ["maintainability", "reliability"]) = 1
|
||||
}
|
||||
|
||||
private predicate reliabilitySubCategory(QueryDoc doc) {
|
||||
doc.getQueryTags() = ["correctness", "performance", "concurrency", "error-handling"]
|
||||
doc.getAQueryTag() = ["correctness", "performance", "concurrency", "error-handling"]
|
||||
}
|
||||
|
||||
private predicate maintainabilitySubCategory(QueryDoc doc) {
|
||||
doc.getQueryTags() = ["readability", "useless-code", "complexity"]
|
||||
doc.getAQueryTag() = ["readability", "useless-code", "complexity"]
|
||||
}
|
||||
|
||||
from TopLevel t, QueryDoc doc, string msg
|
||||
@@ -30,18 +30,18 @@ where
|
||||
not t.getLocation().getFile() instanceof TestFile and
|
||||
hasQualityTag(doc) and
|
||||
(
|
||||
incorrectTopLevelCategorisation(doc) and
|
||||
not correctTopLevelCategorisation(doc) and
|
||||
msg =
|
||||
"This query file has incorrect top-level categorisation. It should have exactly one top-level category, either `@tags maintainability` or `@tags reliability`."
|
||||
or
|
||||
maintainabilitySubCategory(doc) and
|
||||
not doc.getQueryTags() = "maintainability" and
|
||||
not doc.getAQueryTag() = "maintainability" and
|
||||
msg =
|
||||
"This query file has a sub-category of maintainability but is missing the `@tags maintainability` tag."
|
||||
or
|
||||
reliabilitySubCategory(doc) and
|
||||
not doc.getQueryTags() = "reliability" and
|
||||
not doc.getAQueryTag() = "reliability" and
|
||||
msg =
|
||||
"This query file has a sub-category of reliability but is missing the `@tags reliability` tag."
|
||||
)
|
||||
select t, msg
|
||||
select doc, msg
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @name Missing security metadata
|
||||
* @description Security queries should have both a `@tag security` and a `@security-severity` tag.
|
||||
* @description Security queries should have both a `@tags security` and a `@security-severity` tag.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @precision very-high
|
||||
@@ -11,7 +11,7 @@
|
||||
import ql
|
||||
|
||||
predicate missingSecuritySeverity(QueryDoc doc) {
|
||||
doc.getQueryTags() = "security" and
|
||||
doc.getAQueryTag() = "security" and
|
||||
exists(doc.getQueryPrecision()) and
|
||||
not exists(doc.getQuerySecuritySeverity())
|
||||
}
|
||||
@@ -19,7 +19,7 @@ predicate missingSecuritySeverity(QueryDoc doc) {
|
||||
predicate missingSecurityTag(QueryDoc doc) {
|
||||
exists(doc.getQuerySecuritySeverity()) and
|
||||
exists(doc.getQueryPrecision()) and
|
||||
not doc.getQueryTags() = "security"
|
||||
not doc.getAQueryTag() = "security"
|
||||
}
|
||||
|
||||
from TopLevel t, QueryDoc doc, string msg
|
||||
@@ -32,4 +32,4 @@ where
|
||||
or
|
||||
missingSecurityTag(doc) and msg = "This query file is missing a `@tags security`."
|
||||
)
|
||||
select t, msg
|
||||
select doc, msg
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
| testcases/BadQualityMaintainabilityWrongToplevel.ql:1:1:17:13 | TopLevel | This query file has a sub-category of reliability but is missing the `@tags reliability` tag. |
|
||||
| testcases/BadQualityMultipleTopLevel.ql:1:1:17:13 | TopLevel | This query file has incorrect top-level categorisation. It should have exactly one top-level category, either `@tags maintainability` or `@tags reliability`. |
|
||||
| testcases/BadQualityNoToplevel.ql:1:1:16:13 | TopLevel | This query file has incorrect top-level categorisation. It should have exactly one top-level category, either `@tags maintainability` or `@tags reliability`. |
|
||||
| testcases/BadQualityReliabilityWrongToplevel.ql:1:1:17:13 | TopLevel | This query file has a sub-category of maintainability but is missing the `@tags maintainability` tag. |
|
||||
| testcases/BadQualityMaintainabilityWrongToplevel.ql:1:1:11:3 | QueryDoc | This query file has a sub-category of reliability but is missing the `@tags reliability` tag. |
|
||||
| testcases/BadQualityMultipleTopLevel.ql:1:1:11:3 | QueryDoc | This query file has incorrect top-level categorisation. It should have exactly one top-level category, either `@tags maintainability` or `@tags reliability`. |
|
||||
| testcases/BadQualityNoToplevel.ql:1:1:10:3 | QueryDoc | This query file has incorrect top-level categorisation. It should have exactly one top-level category, either `@tags maintainability` or `@tags reliability`. |
|
||||
| testcases/BadQualityReliabilityWrongToplevel.ql:1:1:11:3 | QueryDoc | This query file has a sub-category of maintainability but is missing the `@tags maintainability` tag. |
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
| testcases/BadNoSecurity.ql:1:1:16:9 | TopLevel | This query file is missing a `@tags security`. |
|
||||
| testcases/BadNoSeverity.ql:1:1:16:9 | TopLevel | This query file is missing a `@security-severity` tag. |
|
||||
| testcases/BadNoSecurity.ql:1:1:10:3 | QueryDoc | This query file is missing a `@tags security`. |
|
||||
| testcases/BadNoSeverity.ql:1:1:10:3 | QueryDoc | This query file is missing a `@security-severity` tag. |
|
||||
|
||||
Reference in New Issue
Block a user