Skip to content

Commit 5fe06ab

Browse files
committed
Apply suggestions from code review
1 parent a40b7ef commit 5fe06ab

File tree

4 files changed

+54
-45
lines changed

4 files changed

+54
-45
lines changed

docs/codeql/codeql-cli/about-codeql-packs.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ databases. You may also wish to specify the ``tests`` property.
258258
For more information about running tests, see ":doc:`Testing custom queries
259259
<testing-custom-queries>`."
260260

261-
.. _standard-ql-packs:
261+
.. _standard-codeql-packs:
262262

263263
Examples of CodeQL packs in the CodeQL repository
264-
---------------------------------------------~~~~
264+
-------------------------------------------------
265265

266266
Each of the languages in the CodeQL repository has four main CodeQL packs:
267267

@@ -292,6 +292,7 @@ Some extra notes on the following properties:
292292
- ``library``: Indicates that this is a library pack with no executable queries. It is only meant to be used as a dependency for other packs.
293293
- ``dbscheme`` and ``upgrades``: These properties are internal to the CodeQL CLI and should only be defined in the core QL pack for a language.
294294

295+
.. _standard-codeql-query-packs:
295296

296297
Core query pack
297298
~~~~~~~~~~~~~~~

docs/codeql/codeql-cli/analyzing-databases-with-the-codeql-cli.rst

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ You can also run your own custom queries with the ``database analyze`` command.
123123
For more information about preparing your queries to use with the CodeQL CLI,
124124
see ":doc:`Using custom queries with the CodeQL CLI <using-custom-queries-with-the-codeql-cli>`."
125125

126+
If you do not have the CodeQL repository checked out, you can execute the same queries by specifying the query pack name and the path to the queries::
127+
128+
codeql database analyze --download <javascript-database> codeql/javascript-queries:Declarations/UnusedVariable.ql --format=csv --output=js-analysis/js-results.csv
129+
130+
Use the ``--download`` flag to download the query pack if it isn't yet available locally.
131+
132+
.. _run-query-pack:
133+
126134
Running a CodeQL pack
127135
~~~~~~~~~~~~~~~~~~~~~
128136

@@ -136,6 +144,40 @@ pack names and use the ``--download`` flag::
136144
The ``analyze`` command above runs the default suite from ``microsoft/coding-standards v1.0.0`` and the latest version of ``github/security-queries`` on the specified database.
137145
For further information about default suites, see ":ref:`Publishing and using CodeQL packs <publishing-and-using-codeql-packs>`".
138146

147+
Running all queries in a directory
148+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
149+
150+
You can run all the queries located in a directory by providing the directory
151+
path, rather than listing all the individual query files. Paths are searched
152+
recursively, so any queries contained in subfolders will also be executed.
153+
154+
.. pull-quote::
155+
156+
Important
157+
158+
You should avoid specifying the root of a :ref:`core CodeQL query pack
159+
<standard-codeql-query-packs>` when executing ``database analyze``
160+
as it might contain some special queries that aren't designed to be used with
161+
the command. Rather, :ref:`run the query pack <run-query-pack>` to include the
162+
pack's default queries in the analysis, or run one of the
163+
code scanning query suites.
164+
165+
For example, to execute all Python queries contained in the ``Functions`` directory you would run::
166+
167+
codeql database analyze <python-database> ../ql/python/ql/src/Functions/ --format=sarif-latest --output=python-analysis/python-results.sarif
168+
169+
If you do not have the CodeQL repository checked out, you can execute the same queries by specifying the query pack name and the path to the queries::
170+
171+
codeql database analyze --download <python-database> codeql/python-queries:Functions/ --format=sarif-latest --output=python-analysis/python-results.sarif
172+
173+
Use the ``--download`` flag to download the query pack if it isn't yet available locally.
174+
175+
When the analysis has finished, a SARIF results file is generated. Specifying ``--format=sarif-latest`` ensures
176+
that the results are formatted according to the most recent SARIF specification
177+
supported by CodeQL.
178+
179+
.. _including-query-help-for-custom-codeql-queries-in-sarif-files:
180+
139181
Running a subset of queries in a CodeQL pack
140182
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
141183

@@ -196,7 +238,7 @@ CodeQL query suites are ``.qls`` files that use directives to select queries to
196238
based on certain metadata properties. The standard CodeQL packs have metadata that specify
197239
the location of the query suites used by code scanning, so the CodeQL CLI knows where to find these
198240
suite files automatically, and you don't have to specify the full path on the command line.
199-
For more information, see ":ref:`About CodeQL packs <standard-ql-packs>`."
241+
For more information, see ":ref:`About CodeQL packs <standard-codeql-packs>`."
200242

201243
The standard query suites are stored at the following paths in
202244
the CodeQL repository::
@@ -228,40 +270,6 @@ Integrating a CodeQL pack into a code scanning workflow in GitHub
228270
You can use CodeQL query packs in your code scanning setup. This allows you to select query packs published by various sources and use them to analyze your code.
229271
For more information, see "`Using CodeQL query packs in the CodeQL action <https://docs.github.com/en/code-security/secure-coding/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-codeql-query-packs/>`_" or "`Downloading and using CodeQL query packs in your CI system <https://docs.github.com/en/code-security/secure-coding/using-codeql-code-scanning-with-your-existing-ci-system/configuring-codeql-cli-in-your-ci-system#downloading-and-using-codeql-query-packs>`_."
230272

231-
232-
Running all queries in a directory
233-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
234-
235-
You can run all the queries located in a directory by providing the directory
236-
path, rather than listing all the individual query files. Paths are searched
237-
recursively, so any queries contained in subfolders will also be executed.
238-
239-
.. pull-quote::
240-
241-
Important
242-
243-
You shouldn't specify the root of a :doc:`CodeQL pack
244-
<about-codeql-packs>` when executing ``database analyze``
245-
as it contains some special queries that aren't designed to be used with
246-
the command. Rather, to run a wide range of useful queries, run one of the
247-
LGTM.com query suites.
248-
249-
For example, to execute all Python queries contained in the ``Functions`` directory you would run::
250-
251-
codeql database analyze <python-database> ../ql/python/ql/src/Functions/ --format=sarif-latest --output=python-analysis/python-results.sarif
252-
253-
If you do not have the CodeQL repository checked out, you can execute the same queries by specifying the query pack name and the path to the queries:
254-
255-
codeql database analyze --download <python-database> codeql/python-queries:Functions/ --format=sarif-latest --output=python-analysis/python-results.sarif
256-
257-
Use the ``--download`` flag to download the query pack if it isn't yet available locally.
258-
259-
After evaluating, a SARIF results file is generated. Specifying ``--format=sarif-latest`` ensures
260-
that the results are formatted according to the most recent SARIF specification
261-
supported by CodeQL.
262-
263-
.. _including-query-help-for-custom-codeql-queries-in-sarif-files:
264-
265273
Including query help for custom CodeQL queries in SARIF files
266274
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
267275

docs/codeql/codeql-cli/creating-and-working-with-codeql-packs.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ You must specify:
3434

3535
The ``codeql pack init`` command creates the directory structure and configuration files for a CodeQL pack. By default, the command creates a query pack. If you want to create a library pack, you must edit the ``qlpack.yml`` file to explicitly declare the file as a library pack by including the ``library:true`` property.
3636

37-
Modifying an existing legacy CodeQL pack to create a CodeQL pack
38-
----------------------------------------------------------------
37+
Modifying an existing legacy QL pack to create a CodeQL pack
38+
------------------------------------------------------------
3939

4040
If you already have a ``qlpack.yml`` file, you can edit it manually to convert it into a CodeQL pack.
4141

4242
#. Edit the ``name`` property so that it matches the format ``<scope>/<name>``, where ``<scope>`` is the name of the GitHub organization or user account that you will publish to.
4343
#. In the ``qlpack.yml`` file, include a ``version`` property with a semver identifier, as well as an optional ``dependencies`` block.
44-
#. Migrate the list of dependencies in ``libraryPathDependencies`` to the ``dependencies`` block. Specify the version range for each dependency. If the range is unimportant, or you are unsure of compatibility, you can specify ``"*"``, which indicates that any version is acceptable and will default to the latest version when ``codeql pack install`` is run.
44+
#. Migrate the list of dependencies in ``libraryPathDependencies`` to the ``dependencies`` block. Specify the version range for each dependency. If the range is unimportant, or you are unsure of compatibility, you can specify ``"*"``, which indicates that any version is acceptable and will default to the latest version when you run ``codeql pack install``.
4545

4646
For more information about the properties, see ":ref:`About CodeQL packs <about-codeql-packs>`."
4747

@@ -53,7 +53,7 @@ You can add dependencies on CodeQL packs using the command ``codeql pack add``.
5353

5454
codeql pack add <scope>/<name>@x.x.x <scope>/<other-name>
5555

56-
If you leave off the version range, the latest version will be added. Otherwise, the latest version that satisfies the requested range will be added.
56+
If you don't specify a version range, the latest version will be added. Otherwise, the latest version that satisfies the requested range will be added.
5757

5858
This command updates the ``qlpack.yml`` file with the requested dependencies and downloads them into the package cache. Please note that this command will reformat the file and remove all comments.
5959

docs/codeql/codeql-cli/creating-codeql-query-suites.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ suite definition have been executed, the result is a set of selected queries.
1818

1919
.. pull-quote:: Note
2020

21-
Any custom queries that you want to add to a query suite must be in a :doc:`QL
21+
Any custom queries that you want to add to a query suite must be in a :doc:`CodeQL
2222
pack <about-codeql-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>`."
@@ -52,7 +52,7 @@ queries using:
5252
version: ^x.y.z
5353

5454
The ``version`` field is optional and specifies a range of compatible versions of this CodeQL pack.
55-
If the version is excluded, then the most recent version of the pack is used.
55+
If you don't specify a version, then the most recent version of the pack is used.
5656

5757
- A ``qlpack`` instruction---tells CodeQL to resolve queries in the default suite of the
5858
named CodeQL pack::
@@ -65,7 +65,7 @@ queries using:
6565
define a default suite, the `qlpack` instruction will resolve to all of the queries within the pack.
6666

6767
The ``version`` field is optional and specifies a range of compatible versions of this CodeQL pack.
68-
If the version is excluded, then the most recent version of the pack is used.
68+
If you don't specify a version, then the most recent version of the pack is used.
6969

7070
.. pull-quote:: Note
7171

@@ -191,7 +191,7 @@ Existing query suite definitions can be reused by specifying:
191191
version: ^x.y.z
192192

193193
The ``version`` field is optional and specifies a range of compatible versions of this CodeQL pack.
194-
If the version is excluded, then the most recent version of the pack is used.
194+
If you don't specify a version, then the most recent version of the pack is used.
195195

196196
Queries added using an ``import`` instruction can be filtered using subsequent
197197
``exclude`` instructions.

0 commit comments

Comments
 (0)