Skip to content

Commit fa02f82

Browse files
authored
Updating the metadata style guide
Update query-metadata-style-guide.md
2 parents 887942e + dcdc3b8 commit fa02f82

File tree

1 file changed

+53
-23
lines changed

1 file changed

+53
-23
lines changed

docs/query-metadata-style-guide.md

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -125,29 +125,11 @@ Alert queries (`@kind problem` or `path-problem`) support two further properties
125125

126126
## Query tags `@tags`
127127

128-
The `@tags` property is used to define categories that the query relates to. Each alert query should belong to one (or more, if necessary) of the following four top-level categories:
128+
The `@tags` property is used to define the high level category of problem that the query relates to. Each alert query should belong to one of the following two top-level categories, with additional sub-categories:
129129

130-
* `@tags correctness`–for queries that detect incorrect program behavior.
131-
* `@tags maintainability`–for queries that detect patterns that make it harder for developers to make changes to the code.
132-
* `@tags readability`–for queries that detect confusing patterns that make it harder for developers to read the code.
130+
### High level category `@tags`
133131
* `@tags security`–for queries that detect security weaknesses. See below for further information.
134-
135-
There are also more specific `@tags` that can be added. See, the following pages for examples of the low-level tags:
136-
137-
* [C/C++ queries](https://codeql.github.com/codeql-query-help/cpp/)
138-
* [C# queries](https://codeql.github.com/codeql-query-help/csharp/)
139-
* [Go queries](https://codeql.github.com/codeql-query-help/go/)
140-
* [Java queries](https://codeql.github.com/codeql-query-help/java/)
141-
* [JavaScript queries](https://codeql.github.com/codeql-query-help/javascript/)
142-
* [Python queries](https://codeql.github.com/codeql-query-help/python/)
143-
144-
Metric queries (`@kind metric`) may have the `summary` tag. If SARIF output is used, the results of these queries can be found at `run[].properties.metricResults`.
145-
146-
If necessary, you can also define your own low-level tags to categorize the queries specific to your project or organization. When creating your own tags, you should:
147-
148-
* Use all lower-case letters, including for acronyms and proper nouns, with no spaces. All characters apart from * and @ are accepted.
149-
* Use a forward slash / to indicate a hierarchical relationship between tags if necessary. For example, a query with tag `foo/bar` is also interpreted as also having tag `foo`, but not `bar`.
150-
* Use a single-word `@tags` name. Multiple words, separated with hyphens, can be used for clarity if necessary.
132+
* `@tags quality`–for queries that detect code quality issues. See below for further information.
151133

152134
#### Security query `@tags`
153135

@@ -164,13 +146,61 @@ When you tag a query like this, the associated CWE pages from [MITRE.org](https:
164146
> [!NOTE]
165147
> The automatic addition of CWE reference links works only if the qhelp file already contains a `<references>` section.
166148
167-
#### Metric/summary `@tags`
149+
#### Quality query sub-category `@tags`
168150

169-
Code Scanning may use tags to identify queries with specific meanings across languages. Currently, there is only one such tag: `lines-of-code`. The sum of the results for queries with this tag that return a single number column ([example for JavaScript](https://github.com/github/codeql/blob/c47d680d65f09a851e41d4edad58ffa7486b5431/java/ql/src/Metrics/Summaries/LinesOfCode.ql)) is interpreted by Code Scanning as the lines of code under the source root present in the database. Each language should have exactly one query of this form.
151+
* `@tags maintainability`–for queries that detect patterns that make it harder for developers to make changes to the code.
152+
* `@tags reliability`–for queries that detect issues that affect whether the code will perform as expected during execution.
170153

154+
Software quality doesn't have as universally-agreed categorization method as security issues like CWE, so we will do our own categorization instead of using tags like CWE.
155+
156+
We'll use two "top-level" categories of quality queries, with sub-categories beneath:
157+
158+
* `@tags maintainability`–for queries that detect patterns that make it harder for developers to make changes to the code.
159+
* `@tags readability`–for queries that detect confusing patterns that make it harder for developers to read the code.
160+
* `@tags useless-code`-for queries that detect functions that are never used and other instances of unused code
161+
* `@tags complexity`-for queries that detect patterns in the code that lead to unnecesary complexity such as unclear control flow, or high cyclomatic complexity
162+
163+
164+
* `@tags reliability`–for queries that detect issues that affect whether the code will perform as expected during execution.
165+
* `@tags correctness`–for queries that detect incorrect program behavior or couse result in unintended outcomes.
166+
* `@tags performance`-for queries that detect code that could impact performance through inefficient algorithms, unnecessary computation, etc
167+
* `@tags concurrency`-for queries that detect concurrency related issues such as race conditions, deadlocks, thread safety, etc
168+
* `@tags error-handling`-for queries that detect issues related to unsafe error handling such as uncaught exceptions, etc
169+
170+
171+
There are also more specific `@tags` that can be added. See, the following pages for examples of the low-level tags:
172+
173+
* [C/C++ queries](https://codeql.github.com/codeql-query-help/cpp/)
174+
* [C# queries](https://codeql.github.com/codeql-query-help/csharp/)
175+
* [Go queries](https://codeql.github.com/codeql-query-help/go/)
176+
* [Java queries](https://codeql.github.com/codeql-query-help/java/)
177+
* [JavaScript queries](https://codeql.github.com/codeql-query-help/javascript/)
178+
* [Python queries](https://codeql.github.com/codeql-query-help/python/)
179+
180+
> [!NOTE]
181+
> There is a limit of 10 tags per query!
182+
183+
### Severities
171184

172185
Maintainers are expected to add a `@security-severity` tag to security relevant queries that will be run on Code Scanning. There is a documented internal process for generating these `@security-severity` values.
173186

187+
We will use the `problem.severity` attribute to handle the severity for quality-related queries.
188+
189+
### Metric/summary `@tags`
190+
191+
Code Scanning may use tags to identify queries with specific meanings across languages. Currently, there is only one such tag: `lines-of-code`. The sum of the results for queries with this tag that return a single number column ([example for JavaScript](https://github.com/github/codeql/blob/c47d680d65f09a851e41d4edad58ffa7486b5431/java/ql/src/Metrics/Summaries/LinesOfCode.ql)) is interpreted by Code Scanning as the lines of code under the source root present in the database. Each language should have exactly one query of this form.
192+
193+
Metric queries (`@kind metric`) may have the `summary` tag. If SARIF output is used, the results of these queries can be found at `run[].properties.metricResults`.
194+
195+
196+
### Customizing tags
197+
198+
If necessary, you can also define your own low-level tags to categorize the queries specific to your project or organization, but if possible, please try to follow the above standards (or propose changes to this style guide). When creating your own tags, you should:
199+
200+
* Use all lower-case letters, including for acronyms and proper nouns, with no spaces. All characters apart from * and @ are accepted.
201+
* Use a forward slash / to indicate a hierarchical relationship between tags if necessary. For example, a query with tag `foo/bar` is also interpreted as also having tag `foo`, but not `bar`.
202+
* Use a single-word `@tags` name. Multiple words, separated with hyphens, can be used for clarity if necessary.
203+
174204
## QL area
175205

176206
### Alert messages

0 commit comments

Comments
 (0)