-
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
Open
michaelnebel
wants to merge
10
commits into
github:main
Choose a base branch
from
michaelnebel:ql4ql/qualitytagcheck
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cce1774
Ql4Ql: Re-factor the ql/mising-security-metadata query.
michaelnebel c46b528
Ql4Ql: Add some quality tag testcases.
michaelnebel e00b535
Ql4Ql: Add a check for quality tag consistency.
michaelnebel 60a1d02
Ql4Ql: Add MissingQualityMetadata test.
michaelnebel af1c4e0
Ql4Ql: Share the definition of TestFile between multiple tests.
michaelnebel f58064e
Ql4Ql: Address review comments.
michaelnebel b79e2dd
Ql4Ql: Add some more quality tag testcases.
michaelnebel f810e17
Ql4Ql: Address review comments and update expected test output.
michaelnebel aefd941
Java/Javascript: Fix violations.
michaelnebel 11c4a63
Quality tags: Clarify the quality sub-category tagging policy.
michaelnebel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* @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.getAQueryTag() = "quality" } | ||
|
||
private predicate correctTopLevelCategorisation(QueryDoc doc) { | ||
strictcount(string s | s = doc.getAQueryTag() and s = ["maintainability", "reliability"]) = 1 | ||
} | ||
|
||
private predicate reliabilitySubCategory(QueryDoc doc) { | ||
doc.getAQueryTag() = ["correctness", "performance", "concurrency", "error-handling"] | ||
} | ||
|
||
private predicate maintainabilitySubCategory(QueryDoc doc) { | ||
doc.getAQueryTag() = ["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 | ||
( | ||
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 | ||
correctTopLevelCategorisation(doc) and | ||
( | ||
doc.getAQueryTag() = "reliability" and | ||
not reliabilitySubCategory(doc) and | ||
maintainabilitySubCategory(doc) and | ||
msg = | ||
"This query file has a sub-category of maintainability but has the `@tags reliability` tag." | ||
or | ||
doc.getAQueryTag() = "maintainability" and | ||
not maintainabilitySubCategory(doc) and | ||
reliabilitySubCategory(doc) and | ||
msg = | ||
"This query file has a sub-category of reliability but has the `@tags maintainability` tag." | ||
) | ||
) | ||
select doc, msg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
ql/ql/test/queries/style/MissingQualityMetadata/MissingQualityMetadata.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
| testcases/BadQualityMaintainabilityWrongToplevel.ql:1:1:11:3 | QueryDoc | This query file has a sub-category of reliability but has the `@tags maintainability` 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 has the `@tags reliability` tag. | |
1 change: 1 addition & 0 deletions
1
ql/ql/test/queries/style/MissingQualityMetadata/MissingQualityMetadata.qlref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
queries/style/MissingQualityMetadata.ql | ||
Empty file.
17 changes: 17 additions & 0 deletions
17
.../queries/style/MissingQualityMetadata/testcases/BadQualityMaintainabilityWrongToplevel.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "" |
Empty file.
17 changes: 17 additions & 0 deletions
17
ql/ql/test/queries/style/MissingQualityMetadata/testcases/BadQualityMultipleTopLevel.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "" |
Empty file.
16 changes: 16 additions & 0 deletions
16
ql/ql/test/queries/style/MissingQualityMetadata/testcases/BadQualityNoToplevel.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "" |
Empty file.
17 changes: 17 additions & 0 deletions
17
...test/queries/style/MissingQualityMetadata/testcases/BadQualityReliabilityWrongToplevel.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "" |
Empty file.
16 changes: 16 additions & 0 deletions
16
ql/ql/test/queries/style/MissingQualityMetadata/testcases/GoodNotQuality.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "" |
Empty file.
17 changes: 17 additions & 0 deletions
17
ql/ql/test/queries/style/MissingQualityMetadata/testcases/GoodQualityMaintainability.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "" |
Empty file.
18 changes: 18 additions & 0 deletions
18
.../queries/style/MissingQualityMetadata/testcases/GoodQualityMaintainabilityWithCrossSub.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @name Some query | ||
* @description Some description | ||
* @kind problem | ||
* @problem.severity warning | ||
* @precision very-high | ||
* @id ql/quality-query-test | ||
* @tags quality | ||
* maintainability | ||
* readability | ||
* correctness | ||
*/ | ||
|
||
import ql | ||
|
||
from Class c | ||
where none() | ||
select c, "" |
Empty file.
17 changes: 17 additions & 0 deletions
17
.../test/queries/style/MissingQualityMetadata/testcases/GoodQualityMaintainabilityWithSub.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "" |
Empty file.
16 changes: 16 additions & 0 deletions
16
ql/ql/test/queries/style/MissingQualityMetadata/testcases/GoodQualityReliability.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "" |
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Query test without inline test expectations Warning test