@@ -118,8 +118,10 @@ typically a query metadata property. The value can be:
118
118
119
119
To match a constraint, a metadata value must match one of the strings or
120
120
regular expressions. When there is more than one metadata key, each key must be matched.
121
- For more information about query metadata properties, see ":ref: `Metadata for CodeQL queries
122
- <metadata-for-codeql-queries>`."
121
+ The standard metadata keys available to match on are: ``description ``, ``id ``, ``kind ``,
122
+ ``name ``, ``tags ``, ``precision ``, ``problem.severity ``, and ``security-severity ``.
123
+ For more information about query metadata properties, see
124
+ ":ref: `Metadata for CodeQL queries <metadata-for-codeql-queries >`."
123
125
124
126
In addition to metadata tags, the keys in the constraint block can also be:
125
127
@@ -131,8 +133,36 @@ In addition to metadata tags, the keys in the constraint block can also be:
131
133
- ``tags contain all ``---each of the given match strings must match one of the
132
134
components of the ``@tags `` metadata property.
133
135
134
- Examples
135
- ~~~~~~~~
136
+ Filtering Examples
137
+ ~~~~~~~~~~~~~~~~~~
138
+
139
+ A common use case is to create a query suite that runs all queries in a CodeQL pack,
140
+ except for a few that are known to be problematic. The following three query suite
141
+ definitions are semantically identical:
142
+
143
+ Matches all queries in ``codeql/cpp-queries ``, except for the two queries with either given ``id ``::
144
+
145
+ - qlpack: codeql/cpp-queries
146
+ - exclude:
147
+ id:
148
+ - cpp/cleartext-transmission
149
+ - cpp/cleartext-storage-file
150
+
151
+ As above, but splits the matching into two ``exclude `` instructions::
152
+
153
+ - qlpack: codeql/cpp-queries
154
+ - exclude:
155
+ id: cpp/cleartext-transmission
156
+ - exclude:
157
+ id: cpp/cleartext-storage-file
158
+
159
+ As above, but uses a regular expression to match the ``id `` (assuming
160
+ that the regular expression matches exactly the previous queries)::
161
+
162
+ - qlpack: codeql/cpp-queries
163
+ - exclude:
164
+ id:
165
+ - /^cpp\/cleartext-.*/
136
166
137
167
To define a suite that selects all queries in the default suite of the
138
168
``codeql/cpp-queries `` CodeQL pack, and then refines them to only include
@@ -150,6 +180,15 @@ and ``@precision high`` from the ``my-custom-queries`` directory, use::
150
180
kind: problem
151
181
precision: very-high
152
182
183
+ Note that the following query suite definition is not equivalent. This definition will select
184
+ queries that are ``@kind problem `` *or * are ``@precision very-high ``::
185
+
186
+ - queries: my-custom-queries
187
+ - include:
188
+ kind: problem
189
+ - include:
190
+ precision: very-high
191
+
153
192
To create a suite that selects all queries with ``@kind problem `` from the
154
193
``my-custom-queries `` directory except those with ``@problem.severity
155
194
recommendation ``, use::
@@ -172,6 +211,13 @@ use::
172
211
- high
173
212
- very-high
174
213
214
+ .. pull-quote ::
215
+
216
+ Tip
217
+
218
+ You can use the ``codeql resolve queries /path/to/suite.qls `` command to see
219
+ which queries are selected by a query suite definition.
220
+
175
221
Reusing existing query suite definitions
176
222
-----------------------------------------
177
223
@@ -208,14 +254,8 @@ Existing query suite definitions can be reused by specifying:
208
254
conditions, saved in a ``.yml `` file, to multiple query definitions. For more
209
255
information, see the `example <#example >`__ below.
210
256
211
- - An ``eval `` instruction---performs the same function as an ``import ``
212
- instruction, but takes a full suite definition as the argument, rather than the
213
- path to a ``.qls `` file on disk.
214
-
215
- To see what queries are included in a query suite, you can run the ``codeql resolve queries my-suite.qls `` command.
216
-
217
- Example
218
- ~~~~~~~
257
+ Reusability Examples
258
+ ~~~~~~~~~~~~~~~~~~~~
219
259
220
260
To use the same conditions in multiple query suite definitions, create a
221
261
separate ``.yml `` file containing your instructions. For example, save the
@@ -252,6 +292,30 @@ instruction::
252
292
from: my-org/my-custom-instructions
253
293
version: ^1.2.3 # optional
254
294
295
+ A common use case an ``import `` instruction is to apply a further filter to queries from another
296
+ query suite. For example, this suite will further filter the ``cpp-security-and-quality `` suite
297
+ and exclude ``low `` and ``medium `` precision queries::
298
+
299
+ - import: codeql-suites/cpp-security-and-quality.qls
300
+ from: codeql/cpp-queries
301
+ - exclude:
302
+ precision:
303
+ - low
304
+ - medium
305
+
306
+ If you want to ``include `` queries imported from another suite, the syntax is a little different::
307
+
308
+ - import: codeql-suites/cpp-security-and-quality.qls
309
+ from: codeql/cpp-queries
310
+ - exclude: {}
311
+ - include:
312
+ precision:
313
+ - very-high
314
+ - high
315
+
316
+ Notice the empty ``exclude `` instruction. This is required to ensure that the subsequent ``include ``
317
+ instruction is able to filter queries from the imported suite.
318
+
255
319
Naming a query suite
256
320
--------------------
257
321
0 commit comments