@@ -4,8 +4,8 @@ Creating CodeQL query suites
4
4
============================
5
5
6
6
CodeQL query suites provide a way of selecting queries, based on their
7
- filename, location on disk or in a QL pack, or metadata properties.
8
- Create query suites for the queries that you want to frequently use in
7
+ filename, location on disk or in a QL pack, or metadata properties.
8
+ Create query suites for the queries that you want to frequently use in
9
9
your CodeQL analyses.
10
10
11
11
Query suites allow you to pass multiple queries to
@@ -19,7 +19,7 @@ suite definition have been executed, the result is a set of selected queries.
19
19
.. pull-quote :: Note
20
20
21
21
Any custom queries that you want to add to a query suite must be in a :doc: `QL
22
- pack <about-ql-packs>` and contain the correct query metadata.
22
+ pack <about-ql-packs>` and contain the correct query metadata.
23
23
For more information, see
24
24
":doc: `Using custom queries with the CodeQL CLI <using-custom-queries-with-the-codeql-cli >`."
25
25
@@ -50,10 +50,15 @@ queries using:
50
50
- queries: <path-to-subdirectory>
51
51
from: <ql-pack-name>
52
52
53
- - A ``qlpack `` instruction---tells CodeQL to look for queries in a named QL pack::
53
+ - A ``qlpack `` instruction---tells CodeQL to resolve queries in the default suite of the
54
+ named QL pack::
54
55
55
56
- qlpack: <qlpack-name>
56
57
58
+ The default suite of a query pack includes a recommended set of queries
59
+ inside of that query pack. Not all query packs have a default suite. If the given query pack does not
60
+ define a default suite, the `qlpack ` instruction will resolve to all of the queries within the pack.
61
+
57
62
.. pull-quote :: Note
58
63
59
64
When pathnames appear in query suite definitions, they must always
@@ -73,7 +78,7 @@ Filtering the queries in a query suite
73
78
After you have defined the initial set of queries to add to your suite by
74
79
specifying ``query ``, ``queries ``, or ``qlpack `` instructions, you can add
75
80
``include `` and ``exclude `` instructions. These instructions define selection
76
- criteria based on specific properties:
81
+ criteria based on specific properties:
77
82
78
83
- When you execute an ``include `` instruction on a set of queries, any
79
84
queries that match your conditions are retained in the selection, and queries
@@ -99,20 +104,20 @@ For both instructions, the argument is a constraint block---that is, a YAML map
99
104
representing the constraints. Each constraint is a map entry, where the key is
100
105
typically a query metadata property. The value can be:
101
106
102
- - A single string.
107
+ - A single string.
103
108
- A ``/ ``\ -enclosed `regular expression <https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/regex/Pattern.html >`__.
104
109
- A list containing strings, regular expressions, or both.
105
110
106
111
To match a constraint, a metadata value must match one of the strings or
107
- regular expressions. When there is more than one metadata key, each key must be matched.
112
+ regular expressions. When there is more than one metadata key, each key must be matched.
108
113
For more information about query metadata properties, see ":ref: `Metadata for CodeQL queries
109
114
<metadata-for-codeql-queries>`."
110
115
111
116
In addition to metadata tags, the keys in the constraint block can also be:
112
117
113
118
- ``query filename ``---matches on the last path component of the query file name.
114
119
- ``query path ``---matches on the path to the query file relative to its
115
- enclosing QL pack.
120
+ enclosing QL pack.
116
121
- ``tags contain ``---one of the given match strings must match
117
122
one of the space-separated components of the value of the ``@tags `` metadata property.
118
123
- ``tags contain all ``---each of the given match strings must match one of the
@@ -121,6 +126,14 @@ In addition to metadata tags, the keys in the constraint block can also be:
121
126
Examples
122
127
~~~~~~~~
123
128
129
+ To define a suite that selects all queries in the default suite of the
130
+ ``codeql/cpp-queries `` QL pack, and then refines them to only include
131
+ security queries, use::
132
+
133
+ - qlpack: codeql/cpp-queries
134
+ - include:
135
+ tags contain: security
136
+
124
137
To define a suite that selects all queries with ``@kind problem ``
125
138
and ``@precision high `` from the ``my-custom-queries `` directory, use::
126
139
@@ -136,34 +149,35 @@ recommendation``, use::
136
149
- queries: my-custom-queries
137
150
- include:
138
151
kind: problem
139
- - exclude:
152
+ - exclude:
140
153
problem.severity: recommendation
141
154
142
155
To create a suite that selects all queries with ``@tag security `` and
143
- ``@problem.severity high `` or ``very-high `` from the ``codeql- cpp `` QL pack,
156
+ ``@problem.severity high `` or ``very-high `` from the ``codeql/ cpp-queries `` QL pack,
144
157
use::
145
158
146
- - qlpack: codeql-cpp
147
- - include:
159
+ - queries: .
160
+ from: codeql/cpp-queries
161
+ - include:
148
162
tags contain: security
149
- problem.severity:
163
+ problem.severity:
150
164
- high
151
165
- very-high
152
166
153
167
Reusing existing query suite definitions
154
168
-----------------------------------------
155
169
156
- Existing query suite definitions can be reused by specifying:
170
+ Existing query suite definitions can be reused by specifying:
157
171
158
172
- An ``import `` instruction---adds the queries selected by a
159
173
previously defined ``.qls `` file to the current suite::
160
-
174
+
161
175
- import: <path-to-query-suite>
162
176
163
177
The path to the imported suite must be relative to the QL pack containing the
164
178
current suite definition. If the imported query suite is in a different QL
165
179
pack you can use::
166
-
180
+
167
181
- import: <path-to-query-suite>
168
182
from: <ql-pack>
169
183
@@ -175,12 +189,12 @@ Existing query suite definitions can be reused by specifying:
175
189
applied ``.qls `` file are executed as if they appear in place of ``apply ``.
176
190
Any ``include `` and ``exclude `` instructions from the applied suite also act on
177
191
queries added by any earlier instructions::
178
-
192
+
179
193
- apply: <path-to-query-suite>
180
194
181
195
The ``apply `` instruction can also be used to apply a set of reusable
182
196
conditions, saved in a ``.yml `` file, to multiple query definitions. For more
183
- information, see the `example <#example >`__ below.
197
+ information, see the `example <#example >`__ below.
184
198
185
199
- An ``eval `` instruction---performs the same function as an ``import ``
186
200
instruction, but takes a full suite definition as the argument, rather than the
@@ -236,7 +250,7 @@ instruction::
236
250
This value is displayed when you run `codeql resolve queries
237
251
<../manual/resolve-queries> `__, if the suite is added to a "well-known"
238
252
directory. For more information, see "`Specifying well-known query suites
239
- <#specifying-well-known-query-suites> `__."
253
+ <#specifying-well-known-query-suites> `__."
240
254
241
255
Saving a query suite
242
256
--------------------
@@ -248,8 +262,8 @@ Specifying well-known query suites
248
262
----------------------------------
249
263
250
264
You can use QL packs to declare directories that contain "well-known" query
251
- suites. You can use "well-known" query suites on the command line by referring
252
- to their file name,
265
+ suites. You can use "well-known" query suites on the command line by referring
266
+ to their file name,
253
267
without providing their full path. This gives you a simple way of specifying a
254
268
set of queries, without needing to search inside QL packs and distributions.
255
269
To declare a directory that contains "well-known" query suites, add the directory
@@ -263,7 +277,7 @@ You can specify query suites on the command line for any command that accepts
263
277
``.qls `` files. For example, you can compile the queries selected by a suite
264
278
definition using ``query compile ``, or use the queries in an analysis using
265
279
``database analyze ``. For more information about analyzing CodeQL databases, see
266
- ":doc: `Analyzing databases with the CodeQL CLI <analyzing-databases-with-the-codeql-cli >`."
280
+ ":doc: `Analyzing databases with the CodeQL CLI <analyzing-databases-with-the-codeql-cli >`."
267
281
268
282
Viewing the query suites used on LGTM.com
269
283
-----------------------------------------
0 commit comments