You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/codeql/codeql-cli/creating-codeql-query-suites.rst
+79-12Lines changed: 79 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -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``, and ``problem.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,37 @@ 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
+
Examples of filtering which queries are run
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 specific queries that the user does not want to run. In general, we
141
+
recommend filtering on the query ``id``, which is a unique and stable identifier for
142
+
each query. The following three query suite definitions are semantically identical and
143
+
filter by the query ``id``:
144
+
145
+
This filter matches all the queries in the default suite of ``codeql/cpp-queries``, except for the two queries with the excluded identifiers::
146
+
147
+
- qlpack: codeql/cpp-queries
148
+
- exclude:
149
+
id:
150
+
- cpp/cleartext-transmission
151
+
- cpp/cleartext-storage-file
152
+
153
+
In this example, a separate ``exclude`` instruction is used for each query::
154
+
155
+
- qlpack: codeql/cpp-queries
156
+
- exclude:
157
+
id: cpp/cleartext-transmission
158
+
- exclude:
159
+
id: cpp/cleartext-storage-file
160
+
161
+
In this example, a regular expression excludes the same two queries. It would also exclude any future queries added to the suite with identifiers that begin: ``cpp/cleartext-``::
162
+
163
+
- qlpack: codeql/cpp-queries
164
+
- exclude:
165
+
id:
166
+
- /^cpp\/cleartext-.*/
136
167
137
168
To define a suite that selects all queries in the default suite of the
138
169
``codeql/cpp-queries`` CodeQL pack, and then refines them to only include
@@ -150,6 +181,15 @@ and ``@precision high`` from the ``my-custom-queries`` directory, use::
150
181
kind: problem
151
182
precision: very-high
152
183
184
+
Note that the following query suite definition behaves differently from the definition above. This definition selects queries that are ``@kind problem`` *or*
185
+
are ``@precision very-high``::
186
+
187
+
- queries: my-custom-queries
188
+
- include:
189
+
kind: problem
190
+
- include:
191
+
precision: very-high
192
+
153
193
To create a suite that selects all queries with ``@kind problem`` from the
154
194
``my-custom-queries`` directory except those with ``@problem.severity
155
195
recommendation``, use::
@@ -172,6 +212,15 @@ use::
172
212
- high
173
213
- very-high
174
214
215
+
.. pull-quote::
216
+
217
+
Tip
218
+
219
+
You can use the ``codeql resolve queries /path/to/suite.qls`` command to see
220
+
which queries are selected by a query suite definition. For more information,
221
+
see the `resolve queries <../../codeql-cli/manual/resolve-queries>`__
222
+
reference documentation.
223
+
175
224
Reusing existing query suite definitions
176
225
-----------------------------------------
177
226
@@ -208,14 +257,8 @@ Existing query suite definitions can be reused by specifying:
208
257
conditions, saved in a ``.yml`` file, to multiple query definitions. For more
209
258
information, see the `example <#example>`__ below.
210
259
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
-
~~~~~~~
260
+
Reusability Examples
261
+
~~~~~~~~~~~~~~~~~~~~
219
262
220
263
To use the same conditions in multiple query suite definitions, create a
221
264
separate ``.yml`` file containing your instructions. For example, save the
@@ -252,6 +295,30 @@ instruction::
252
295
from: my-org/my-custom-instructions
253
296
version: ^1.2.3 # optional
254
297
298
+
A common use case for an ``import`` instruction is to apply a further filter to queries from another
299
+
query suite. For example, this suite will further filter the ``cpp-security-and-quality`` suite
300
+
and exclude ``low`` and ``medium`` precision queries::
0 commit comments