|
| 1 | +/** |
| 2 | + * @name Missing quality metadata |
| 3 | + * @description Quality queries should have exactly one top-level category and if sub-categories are used, the appropriate top-level category should be used. |
| 4 | + * @kind problem |
| 5 | + * @problem.severity warning |
| 6 | + * @precision very-high |
| 7 | + * @id ql/missing-security-metadata |
| 8 | + * @tags correctness |
| 9 | + */ |
| 10 | + |
| 11 | +import ql |
| 12 | + |
| 13 | +private predicate unInterestingLocation(File f) { |
| 14 | + f.getRelativePath().matches("%/" + ["experimental", "examples", "test"] + "/%") |
| 15 | +} |
| 16 | + |
| 17 | +private predicate hasQualityTag(QueryDoc doc) { doc.getQueryTags() = "quality" } |
| 18 | + |
| 19 | +private predicate incorrectTopLevelCategorisation(QueryDoc doc) { |
| 20 | + count(string s | s = doc.getQueryTags() and s = ["maintainability", "reliability"]) != 1 |
| 21 | +} |
| 22 | + |
| 23 | +private predicate reliabilitySubCategory(QueryDoc doc) { |
| 24 | + doc.getQueryTags() = ["correctness", "performance", "concurrency", "error-handling"] |
| 25 | +} |
| 26 | + |
| 27 | +private predicate maintainabilitySubCategory(QueryDoc doc) { |
| 28 | + doc.getQueryTags() = ["readability", "useless-code", "complexity"] |
| 29 | +} |
| 30 | + |
| 31 | +from TopLevel t, QueryDoc doc, string msg |
| 32 | +where |
| 33 | + doc = t.getQLDoc() and |
| 34 | + not unInterestingLocation(t.getLocation().getFile()) and |
| 35 | + hasQualityTag(doc) and |
| 36 | + ( |
| 37 | + incorrectTopLevelCategorisation(doc) and |
| 38 | + msg = |
| 39 | + "This query file has incorrect top-level categorisation. It should have exactly one top-level category, either `@tags maintainability` or `@tags reliability`." |
| 40 | + or |
| 41 | + maintainabilitySubCategory(doc) and |
| 42 | + not doc.getQueryTags() = "maintainability" and |
| 43 | + msg = |
| 44 | + "This query file has a sub-category of maintainability but is missing the `@tags maintainability` tag." |
| 45 | + or |
| 46 | + reliabilitySubCategory(doc) and |
| 47 | + not doc.getQueryTags() = "reliability" and |
| 48 | + msg = |
| 49 | + "This query file has a sub-category of reliability but is missing the `@tags reliability` tag." |
| 50 | + ) |
| 51 | +select t, msg |
0 commit comments