-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Merged
michaelnebel
merged 10 commits into
github:main
from
michaelnebel:ql4ql/qualitytagcheck
Jul 17, 2025
Merged
Changes from 1 commit
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
Ql4Ql: Add a check for quality tag consistency.
- Loading branch information
commit e00b5351a42dfe4b3d60e32796b86f53a1b2a3bf
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /** | ||
| * @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 unInterestingLocation(File f) { | ||
| f.getRelativePath().matches("%/" + ["experimental", "examples", "test"] + "/%") | ||
| } | ||
|
|
||
| private predicate hasQualityTag(QueryDoc doc) { doc.getQueryTags() = "quality" } | ||
|
|
||
| private predicate incorrectTopLevelCategorisation(QueryDoc doc) { | ||
| count(string s | s = doc.getQueryTags() and s = ["maintainability", "reliability"]) != 1 | ||
| } | ||
|
|
||
| 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 unInterestingLocation(t.getLocation().getFile()) 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 | ||
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.
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.
May as well use
strictcount.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.
Uh wait, we can't - the predicate won't hold in the case there is no top level tag (if the count is
0).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.
Well ok, I can invert the logic 😄