| title | Creating a custom query | ||||||
|---|---|---|---|---|---|---|---|
| shortTitle | Custom query creation | ||||||
| versions |
|
||||||
| intro | You can work from a template to write your own code to create a custom query to analyze a specific language. | ||||||
| redirect_from |
|
||||||
| contentType | how-tos | ||||||
| category |
|
You can write custom {% data variables.product.prodname_codeql %} queries to find specific issues relevant to your own project. This is optional, and the github/codeql repository contains a large number of example queries you can use instead.
You create a new query file from a template for a given language, which imports the standard libraries for analyzing that language.
-
In the extension sidebar, open the "Queries" view, then click the Create query icon.
-
In the {% data variables.product.prodname_vscode_command_palette_shortname %}, select the target language for your query. If you've chosen not to create your custom query in an existing directory, selecting a language will autogenerate a directory labeled
codeql-custom-queries-LANGUAGE, whereLANGUAGEis the name of the selected language. A query template labeledexample.qlwill then be added to the existing or autogenerated directory. -
In the template, write your custom query, then save the file. Once your query is finished, you can run it from the "Queries" view.
You can read about how to write queries for supported languages in the {% data variables.product.prodname_codeql %} documentation:
- {% data variables.product.prodname_codeql %} for C and C++
- {% data variables.product.prodname_codeql %} for C#
- {% data variables.product.prodname_codeql %} for Go
- {% data variables.product.prodname_codeql %} for Java and Kotlin
- {% data variables.product.prodname_codeql %} for JavaScript and TypeScript
- {% data variables.product.prodname_codeql %} for Python
- {% data variables.product.prodname_codeql %} for Ruby
- {% data variables.product.prodname_codeql %} for Swift