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)
|
result = this.getContents().regexpCapture("(?s).*@security\\-severity ([\\d\\.]+)\\s.*", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Gets the individual @tags for the query. */
|
/** Gets the individual @tags for the query, if any. */
|
||||||
string getQueryTags() {
|
string getAQueryTag() {
|
||||||
exists(string tags | tags = this.getContents().regexpCapture("(?s).*@tags ([^@]+)", 1) |
|
exists(string tags | tags = this.getContents().regexpCapture("(?s).*@tags ([^@]+)", 1) |
|
||||||
result = tags.splitAt("*").trim() and
|
result = tags.splitAt("*").trim() and
|
||||||
result.regexpMatch("[\\w\\s\\-]+")
|
result.regexpMatch("[\\w\\s\\-]+")
|
||||||
|
|||||||
@@ -10,18 +10,18 @@
|
|||||||
|
|
||||||
import ql
|
import ql
|
||||||
|
|
||||||
private predicate hasQualityTag(QueryDoc doc) { doc.getQueryTags() = "quality" }
|
private predicate hasQualityTag(QueryDoc doc) { doc.getAQueryTag() = "quality" }
|
||||||
|
|
||||||
private predicate incorrectTopLevelCategorisation(QueryDoc doc) {
|
private predicate correctTopLevelCategorisation(QueryDoc doc) {
|
||||||
count(string s | s = doc.getQueryTags() and s = ["maintainability", "reliability"]) != 1
|
strictcount(string s | s = doc.getAQueryTag() and s = ["maintainability", "reliability"]) = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
private predicate reliabilitySubCategory(QueryDoc doc) {
|
private predicate reliabilitySubCategory(QueryDoc doc) {
|
||||||
doc.getQueryTags() = ["correctness", "performance", "concurrency", "error-handling"]
|
doc.getAQueryTag() = ["correctness", "performance", "concurrency", "error-handling"]
|
||||||
}
|
}
|
||||||
|
|
||||||
private predicate maintainabilitySubCategory(QueryDoc doc) {
|
private predicate maintainabilitySubCategory(QueryDoc doc) {
|
||||||
doc.getQueryTags() = ["readability", "useless-code", "complexity"]
|
doc.getAQueryTag() = ["readability", "useless-code", "complexity"]
|
||||||
}
|
}
|
||||||
|
|
||||||
from TopLevel t, QueryDoc doc, string msg
|
from TopLevel t, QueryDoc doc, string msg
|
||||||
@@ -30,18 +30,18 @@ where
|
|||||||
not t.getLocation().getFile() instanceof TestFile and
|
not t.getLocation().getFile() instanceof TestFile and
|
||||||
hasQualityTag(doc) and
|
hasQualityTag(doc) and
|
||||||
(
|
(
|
||||||
incorrectTopLevelCategorisation(doc) and
|
not correctTopLevelCategorisation(doc) and
|
||||||
msg =
|
msg =
|
||||||
"This query file has incorrect top-level categorisation. It should have exactly one top-level category, either `@tags maintainability` or `@tags reliability`."
|
"This query file has incorrect top-level categorisation. It should have exactly one top-level category, either `@tags maintainability` or `@tags reliability`."
|
||||||
or
|
or
|
||||||
maintainabilitySubCategory(doc) and
|
maintainabilitySubCategory(doc) and
|
||||||
not doc.getQueryTags() = "maintainability" and
|
not doc.getAQueryTag() = "maintainability" and
|
||||||
msg =
|
msg =
|
||||||
"This query file has a sub-category of maintainability but is missing the `@tags maintainability` tag."
|
"This query file has a sub-category of maintainability but is missing the `@tags maintainability` tag."
|
||||||
or
|
or
|
||||||
reliabilitySubCategory(doc) and
|
reliabilitySubCategory(doc) and
|
||||||
not doc.getQueryTags() = "reliability" and
|
not doc.getAQueryTag() = "reliability" and
|
||||||
msg =
|
msg =
|
||||||
"This query file has a sub-category of reliability but is missing the `@tags reliability` tag."
|
"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
|
* @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
|
* @kind problem
|
||||||
* @problem.severity warning
|
* @problem.severity warning
|
||||||
* @precision very-high
|
* @precision very-high
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
import ql
|
import ql
|
||||||
|
|
||||||
predicate missingSecuritySeverity(QueryDoc doc) {
|
predicate missingSecuritySeverity(QueryDoc doc) {
|
||||||
doc.getQueryTags() = "security" and
|
doc.getAQueryTag() = "security" and
|
||||||
exists(doc.getQueryPrecision()) and
|
exists(doc.getQueryPrecision()) and
|
||||||
not exists(doc.getQuerySecuritySeverity())
|
not exists(doc.getQuerySecuritySeverity())
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ predicate missingSecuritySeverity(QueryDoc doc) {
|
|||||||
predicate missingSecurityTag(QueryDoc doc) {
|
predicate missingSecurityTag(QueryDoc doc) {
|
||||||
exists(doc.getQuerySecuritySeverity()) and
|
exists(doc.getQuerySecuritySeverity()) and
|
||||||
exists(doc.getQueryPrecision()) and
|
exists(doc.getQueryPrecision()) and
|
||||||
not doc.getQueryTags() = "security"
|
not doc.getAQueryTag() = "security"
|
||||||
}
|
}
|
||||||
|
|
||||||
from TopLevel t, QueryDoc doc, string msg
|
from TopLevel t, QueryDoc doc, string msg
|
||||||
@@ -32,4 +32,4 @@ where
|
|||||||
or
|
or
|
||||||
missingSecurityTag(doc) and msg = "This query file is missing a `@tags security`."
|
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/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: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/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: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/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:17:13 | TopLevel | This query file has a sub-category of maintainability but is missing the `@tags maintainability` tag. |
|
| 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/BadNoSecurity.ql:1:1:10:3 | QueryDoc | 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/BadNoSeverity.ql:1:1:10:3 | QueryDoc | This query file is missing a `@security-severity` tag. |
|
||||||
|
|||||||
Reference in New Issue
Block a user