Skip to main content

此版本的 GitHub Enterprise Server 将于以下日期停止服务 2026-04-09. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

Creating a custom query

You can work from a template to write your own code to create a custom query to analyze a specific language.

在本文中

You can write custom 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.

Creating a custom query

You create a new query file from a template for a given language, which imports the standard libraries for analyzing that language.

  1. In the extension sidebar, open the "Queries" view, then click the Create query icon.

  2. In the VS Code Command Palette, 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, where LANGUAGE is the name of the selected language. A query template labeled example.ql will then be added to the existing or autogenerated directory.

  3. In the template, write your custom query, then save the file. Once your query is finished, you can run it from the "Queries" view.

Further reading

You can read about how to write queries for supported languages in the CodeQL documentation: