Skip to content

Commit e0a123c

Browse files
authored
Merge pull request github#6257 from github/rneatherway/summary-docs
Add docs for summary type queries
2 parents a0481bd + c9e642f commit e0a123c

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

docs/query-metadata-style-guide.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ Note, `@id` properties should be consistent for queries that highlight the same
104104

105105
* alerts (`@kind problem`)
106106
* alerts containing path information (`@kind path-problem`)
107+
* metrics (`@kind metric`)
107108

108109
Alert queries (`@kind problem` or `path-problem`) support two further properties. These are added by GitHub staff after the query has been tested, prior to deployment to LGTM. The following information is for reference:
109110

@@ -123,7 +124,7 @@ The values of `@precision` and `@problem.severity` assigned to a query that is p
123124

124125
## Query tags `@tags`
125126

126-
The `@tags` property is used to define categories that the query relates to. Each query should belong to one (or more, if necessary) of the following four top-level categories:
127+
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:
127128

128129
* `@tags correctness`–for queries that detect incorrect program behavior.
129130
* `@tags maintainability`–for queries that detect patterns that make it harder for developers to make changes to the code.
@@ -139,6 +140,8 @@ There are also more specific `@tags` that can be added. See, the following pages
139140
* [JavaScript queries](https://codeql.github.com/codeql-query-help/javascript/)
140141
* [Python queries](https://codeql.github.com/codeql-query-help/python/)
141142

143+
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`.
144+
142145
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:
143146

144147
* Use all lower-case letters, including for acronyms and proper nouns, with no spaces. All characters apart from * and @ are accepted.
@@ -157,6 +160,11 @@ If your query is a security query, use one or more `@tags` to associate it with
157160

158161
When you tag a query like this, the associated CWE pages from [MITRE.org](https://cwe.mitre.org/index.html) will automatically appear in the reference section of its associated qhelp file.
159162

163+
#### Metric/summary `@tags`
164+
165+
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.
166+
167+
160168
## QL area
161169

162170
### Alert messages
@@ -180,3 +188,13 @@ For examples of select clauses and alert messages, see the query source files at
180188
* [Python queries](https://codeql.github.com/codeql-query-help/python/)
181189

182190
For further information on query writing, see [CodeQL queries](https://codeql.github.com/docs/writing-codeql-queries/codeql-queries/). For more information on learning CodeQL, see [CodeQL documentation](https://codeql.github.com/docs/).
191+
192+
## Metric results
193+
194+
The `select` clause of a summary metric query must have one of the following result patterns:
195+
- Just a `number`
196+
- This indicates a metric without a specific location in the codebase, for example the total lines of code in a codebase.
197+
- A code `entity` followed by a `number`
198+
- This indicates a metric with a specific location in the codebase, for example the lines of code within a file. The `entity` here must have a valid location in the source code.
199+
200+

0 commit comments

Comments
 (0)