@@ -4,8 +4,8 @@ Creating CodeQL query suites
44============================
55
66CodeQL 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
99your CodeQL analyses.
1010
1111Query 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.
1919.. pull-quote :: Note
2020
2121 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.
2323 For more information, see
2424 ":doc: `Using custom queries with the CodeQL CLI <using-custom-queries-with-the-codeql-cli >`."
2525
@@ -50,10 +50,15 @@ queries using:
5050 - queries: <path-to-subdirectory>
5151 from: <ql-pack-name>
5252
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::
5455
5556 - qlpack: <qlpack-name>
5657
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+
5762.. pull-quote :: Note
5863
5964 When pathnames appear in query suite definitions, they must always
@@ -73,7 +78,7 @@ Filtering the queries in a query suite
7378After you have defined the initial set of queries to add to your suite by
7479specifying ``query ``, ``queries ``, or ``qlpack `` instructions, you can add
7580``include `` and ``exclude `` instructions. These instructions define selection
76- criteria based on specific properties:
81+ criteria based on specific properties:
7782
7883- When you execute an ``include `` instruction on a set of queries, any
7984 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
99104representing the constraints. Each constraint is a map entry, where the key is
100105typically a query metadata property. The value can be:
101106
102- - A single string.
107+ - A single string.
103108- A ``/ ``\ -enclosed `regular expression <https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/regex/Pattern.html >`__.
104109- A list containing strings, regular expressions, or both.
105110
106111To 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.
108113For more information about query metadata properties, see ":ref: `Metadata for CodeQL queries
109114<metadata-for-codeql-queries>`."
110115
111116In addition to metadata tags, the keys in the constraint block can also be:
112117
113118- ``query filename ``---matches on the last path component of the query file name.
114119- ``query path ``---matches on the path to the query file relative to its
115- enclosing QL pack.
120+ enclosing QL pack.
116121- ``tags contain ``---one of the given match strings must match
117122 one of the space-separated components of the value of the ``@tags `` metadata property.
118123- ``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:
121126Examples
122127~~~~~~~~
123128
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+
124137To define a suite that selects all queries with ``@kind problem ``
125138and ``@precision high `` from the ``my-custom-queries `` directory, use::
126139
@@ -136,34 +149,35 @@ recommendation``, use::
136149 - queries: my-custom-queries
137150 - include:
138151 kind: problem
139- - exclude:
152+ - exclude:
140153 problem.severity: recommendation
141154
142155To 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,
144157use::
145158
146- - qlpack: codeql-cpp
147- - include:
159+ - queries: .
160+ from: codeql/cpp-queries
161+ - include:
148162 tags contain: security
149- problem.severity:
163+ problem.severity:
150164 - high
151165 - very-high
152166
153167Reusing existing query suite definitions
154168-----------------------------------------
155169
156- Existing query suite definitions can be reused by specifying:
170+ Existing query suite definitions can be reused by specifying:
157171
158172- An ``import `` instruction---adds the queries selected by a
159173 previously defined ``.qls `` file to the current suite::
160-
174+
161175 - import: <path-to-query-suite>
162176
163177 The path to the imported suite must be relative to the QL pack containing the
164178 current suite definition. If the imported query suite is in a different QL
165179 pack you can use::
166-
180+
167181 - import: <path-to-query-suite>
168182 from: <ql-pack>
169183
@@ -175,12 +189,12 @@ Existing query suite definitions can be reused by specifying:
175189 applied ``.qls `` file are executed as if they appear in place of ``apply ``.
176190 Any ``include `` and ``exclude `` instructions from the applied suite also act on
177191 queries added by any earlier instructions::
178-
192+
179193 - apply: <path-to-query-suite>
180194
181195 The ``apply `` instruction can also be used to apply a set of reusable
182196 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.
184198
185199- An ``eval `` instruction---performs the same function as an ``import ``
186200 instruction, but takes a full suite definition as the argument, rather than the
@@ -236,7 +250,7 @@ instruction::
236250This value is displayed when you run `codeql resolve queries
237251<../manual/resolve-queries> `__, if the suite is added to a "well-known"
238252directory. For more information, see "`Specifying well-known query suites
239- <#specifying-well-known-query-suites> `__."
253+ <#specifying-well-known-query-suites> `__."
240254
241255Saving a query suite
242256--------------------
@@ -248,8 +262,8 @@ Specifying well-known query suites
248262----------------------------------
249263
250264You 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,
253267without providing their full path. This gives you a simple way of specifying a
254268set of queries, without needing to search inside QL packs and distributions.
255269To 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
263277``.qls `` files. For example, you can compile the queries selected by a suite
264278definition using ``query compile ``, or use the queries in an analysis using
265279``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 >`."
267281
268282Viewing the query suites used on LGTM.com
269283-----------------------------------------
0 commit comments