Skip to content

Commit 70a2adb

Browse files
authored
[EDI] Testing query help files (#60008)
1 parent 715bff5 commit 70a2adb

File tree

1 file changed

+15
-40
lines changed

1 file changed

+15
-40
lines changed
Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Testing query help files
33
shortTitle: Test query help files
4-
intro: You can use the {% data variables.product.prodname_codeql_cli %} to preview your query help files as Markdown and ensure they are valid.
4+
intro: Ensure your {% data variables.product.prodname_codeql %} query help files are valid by previewing them as Markdown.
55
product: '{% data reusables.gated-features.codeql %}'
66
versions:
77
fpt: '*'
@@ -18,53 +18,28 @@ redirect_from:
1818
contentType: how-tos
1919
---
2020

21-
## About testing query help files
22-
23-
Test query help files by rendering them as Markdown to ensure they are valid before uploading them to the {% data variables.product.prodname_codeql %} repository or using them in code scanning.
24-
25-
<!-- capitalized Markdown -->
26-
27-
Query help is documentation that accompanies a query to explain how the query works, as well as providing information about the potential problem that the query identifies. It is good practice to write query help for all new queries. For more information, see [Contributing to {% data variables.product.prodname_codeql %}](https://github.com/github/codeql/blob/main/CONTRIBUTING.md) in the {% data variables.product.prodname_codeql %} repository.
28-
29-
The {% data variables.product.prodname_codeql_cli %} includes a command to test query help and render the content as markdown, so that you can easily preview the content in your IDE. Use the command to validate query help files before uploading them to the {% data variables.product.prodname_codeql %} repository or sharing them with other users. From {% data variables.product.prodname_codeql_cli %} 2.7.1 onwards, you can also include the markdown-rendered query help in SARIF files
30-
generated during {% data variables.product.prodname_codeql %} analyses so that the query help can be displayed in the code scanning UI. For more information, see [AUTOTITLE](/code-security/codeql-cli/getting-started-with-the-codeql-cli/analyzing-your-code-with-codeql-queries).
31-
3221
## Prerequisites
3322

34-
* The query help (`.qhelp`) file must have an accompanying query (`.ql`) file with an identical base name.
35-
* The query help file should follow the standard structure and style for query help documentation. For more information, see the [Query help style guide](https://github.com/github/codeql/blob/main/docs/query-help-style-guide.md) in the {% data variables.product.prodname_codeql %} repository.
36-
37-
## Running `codeql generate query-help`
38-
39-
You can test query help files by running the following command:
40-
41-
```shell
42-
codeql generate query-help <qhelp|query|dir|suite> --format=<format> [--output=<dir|file>]
43-
```
44-
45-
For this command `<qhelp|query|dir|suite>` must be the path to a `.qhelp` file, the path to a `.ql` file, the path to a directory containing queries and query help files, or the path to a query suite.
46-
47-
You must specify a `--format` option, which defines how the query help is rendered. Currently, you must specify `markdown` to render the query help as markdown.
48-
49-
The `--output` option defines a file path where the rendered query help will be saved.
50-
51-
* For directories containing `.qhelp` files or a query suites defining one or more `.qhelp` files, you must specify an `--output` directory. Filenames within the output directory will be derived from the `.qhelp` file names.
52-
* For single `.qhelp` or `.ql` files, you may specify an `--output` option. If you don’t specify an output path, the rendered query help is written to `stdout`.
53-
54-
For full details of all the options you can use when testing query help files, see [AUTOTITLE](/code-security/codeql-cli/codeql-cli-manual/generate-query-help).
23+
* The query help (`.qhelp`) files must have accompanying query (`.ql`) files with identical base names.
24+
* The query help files should follow the standard structure and style for query help documentation. For more information, see the [Query help style guide](https://github.com/github/codeql/blob/main/docs/query-help-style-guide.md) in the {% data variables.product.prodname_codeql %} repository.
5525

56-
## Results
26+
## Previewing your query help files
5727

58-
When you run the command, {% data variables.product.prodname_codeql %} attempts to render each `.qhelp` file that has an accompanying `.ql` file. For single files, the rendered content will be printed to `stdout` if you don’t specify an `--output` option. For all other use cases, the rendered content is saved to the specified output path.
28+
1. To render your query help files as Markdown, run the following command:
5929

60-
By default, the {% data variables.product.prodname_codeql_cli %} will print a warning message if:
30+
```shell copy
31+
codeql generate query-help <qhelp|query|dir|suite> --format=markdown [--output=<dir|file>]
32+
```
6133

62-
* Any of the query help is invalid, along with a description of the invalid query help elements
63-
* Any `.qhelp` files specified in the command don’t have the same base name as an accompanying `.ql` file
64-
* Any `.ql` files specified in the command don’t have the same base name as an accompanying `.qhelp` file
34+
For information on the options available for this command, see [AUTOTITLE](/code-security/reference/code-scanning/codeql/codeql-cli-manual/generate-query-help).
6535

66-
You can tell the {% data variables.product.prodname_codeql_cli %} how to handle these warnings by including a `--warnings` option in your command. For more information, see [AUTOTITLE](/code-security/codeql-cli/codeql-cli-manual/generate-query-help#--warningsmode).
36+
1. If you receive any warning messages, review and fix them, then rerun the command. By default, the {% data variables.product.prodname_codeql_cli %} will print a warning message if:
37+
* Any of the query help is invalid
38+
* Any `.qhelp` files specified in the command don’t have the same base name as an accompanying `.ql` file
39+
* Any `.ql` files specified in the command don’t have the same base name as an accompanying `.qhelp` file
40+
1. Review the rendered Markdown in your output directory, file, or terminal to check that your files appear as expected.
6741

6842
## Further reading
6943

7044
* [Query help files](https://codeql.github.com/docs/writing-codeql-queries/query-help-files/#query-help-files)
45+
* [AUTOTITLE](/code-security/codeql-cli/codeql-cli-manual/generate-query-help)

0 commit comments

Comments
 (0)