-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Ql4ql: Quality query tagging. #19931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2bec69e
d29804b
d5ff5dc
d484525
033ea97
ce5f119
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* @name Missing quality metadata | ||
* @description Quality queries should have exactly one top-level category and if sub-categories are used, the appropriate top-level category should be used. | ||
* @kind problem | ||
* @problem.severity warning | ||
* @precision very-high | ||
* @id ql/missing-quality-metadata | ||
* @tags correctness | ||
*/ | ||
|
||
import ql | ||
|
||
private predicate hasQualityTag(QueryDoc doc) { doc.getQueryTags() = "quality" } | ||
|
||
private predicate incorrectTopLevelCategorisation(QueryDoc doc) { | ||
count(string s | s = doc.getQueryTags() and s = ["maintainability", "reliability"]) != 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May as well use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uh wait, we can't - the predicate won't hold in the case there is no top level tag (if the count is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well ok, I can invert the logic 😄 |
||
} | ||
|
||
private predicate reliabilitySubCategory(QueryDoc doc) { | ||
doc.getQueryTags() = ["correctness", "performance", "concurrency", "error-handling"] | ||
} | ||
|
||
private predicate maintainabilitySubCategory(QueryDoc doc) { | ||
doc.getQueryTags() = ["readability", "useless-code", "complexity"] | ||
} | ||
|
||
from TopLevel t, QueryDoc doc, string msg | ||
where | ||
doc = t.getQLDoc() and | ||
not t.getLocation().getFile() instanceof TestFile and | ||
hasQualityTag(doc) and | ||
( | ||
incorrectTopLevelCategorisation(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 | ||
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 | ||
msg = | ||
"This query file has a sub-category of reliability but is missing the `@tags reliability` tag." | ||
) | ||
select t, msg |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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. | |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
queries/style/MissingQualityMetadata.ql | ||
Check warningCode scanning / CodeQL Query test without inline test expectations Warning test
Query test does not use inline test expectations.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @name Some query | ||
* @description Some description | ||
* @kind problem | ||
* @problem.severity warning | ||
* @precision very-high | ||
* @id ql/quality-query-test | ||
* @tags quality | ||
* maintainability | ||
* error-handling | ||
*/ | ||
|
||
import ql | ||
|
||
from Class c | ||
where none() | ||
select c, "" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @name Some query | ||
* @description Some description | ||
* @kind problem | ||
* @problem.severity warning | ||
* @precision very-high | ||
* @id ql/quality-query-test | ||
* @tags quality | ||
* maintainability | ||
* reliability | ||
*/ | ||
|
||
import ql | ||
|
||
from Class c | ||
where none() | ||
select c, "" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @name Some query | ||
* @description Some description | ||
* @kind problem | ||
* @problem.severity warning | ||
* @precision very-high | ||
* @id ql/quality-query-test | ||
* @tags quality | ||
* someothertag | ||
*/ | ||
|
||
import ql | ||
|
||
from Class c | ||
where none() | ||
select c, "" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @name Some query | ||
* @description Some description | ||
* @kind problem | ||
* @problem.severity warning | ||
* @precision very-high | ||
* @id ql/quality-query-test | ||
* @tags quality | ||
* reliability | ||
* readability | ||
*/ | ||
|
||
import ql | ||
|
||
from Class c | ||
where none() | ||
select c, "" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @name Some query | ||
* @description Some description | ||
* @kind problem | ||
* @problem.severity warning | ||
* @security-severity 10.0 | ||
* @precision very-high | ||
* @id ql/quality-query-test | ||
* @tags security | ||
*/ | ||
|
||
import ql | ||
|
||
from Class c | ||
where none() | ||
select c, "" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @name Some query | ||
* @description Some description | ||
* @kind problem | ||
* @problem.severity warning | ||
* @security-severity 10.0 | ||
* @precision very-high | ||
* @id ql/quality-query-test | ||
* @tags quality | ||
* maintainability | ||
*/ | ||
|
||
import ql | ||
|
||
from Class c | ||
where none() | ||
select c, "" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @name Some query | ||
* @description Some description | ||
* @kind problem | ||
* @problem.severity warning | ||
* @precision very-high | ||
* @id ql/quality-query-test | ||
* @tags quality | ||
* maintainability | ||
* readability | ||
*/ | ||
|
||
import ql | ||
|
||
from Class c | ||
where none() | ||
select c, "" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* @name Some query | ||
* @description Some description | ||
* @kind problem | ||
* @problem.severity warning | ||
* @precision very-high | ||
* @id ql/quality-query-test | ||
* @tags quality | ||
* reliability | ||
*/ | ||
|
||
import ql | ||
|
||
from Class c | ||
where none() | ||
select c, "" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @name Some query | ||
* @description Some description | ||
* @kind problem | ||
* @problem.severity warning | ||
* @precision very-high | ||
* @id ql/quality-query-test | ||
* @tags quality | ||
* reliability | ||
* correctness | ||
*/ | ||
|
||
import ql | ||
|
||
from Class c | ||
where none() | ||
select c, "" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
| testcases/BadNoSecurity.ql:1:1:16:9 | TopLevel | This query file is missing a `@tag security`. | | ||
| 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. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getAQueryTag
would be a better name.