[clang-tools-extra] [llvm] [clang-tidy] Introduced new option --dump-yaml-schema (PR #164412)

Timur Golubovich via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 23 06:18:17 PDT 2025


tgs-sc wrote:

This is a small pitch:

### A quick introduction to using YAML schemas from the LLVM tool clang-tidy

There are some useful LLVM tools that everyone has used in one way or another, such as clang-format, clang-tidy, and others. These tools usually require some configuration input, which is often provided in YAML format. Similarly, at our company, an LLVM tool is being developed with a very complex input configuration. Usually, this configuration is either copied from project to project or checked against documentation. In this topic, I propose adding an option to clang-tidy that dumps the skeleton of this configuration in YAML schema format. In addition to allowing users to visualize this skeleton, if they use an IDE, they will receive hints when setting up this configuration, since modern IDEs have such support.

# Example

Let's consider an example of setting up the input configuration for clang-tidy in a certain project using VSCode IDE.

## Step 1
Assume you have a certain project that you want to run through clang-tidy.

<img width="1032" height="204" alt="step1" src="https://github.com/user-attachments/assets/6a49deb4-bee0-4cae-a0c2-ecaf778dfae5" />

## Step 2
In VSCode, there may be a `.vscode` folder where local IDE settings for each project are stored. Using the redhat.vscode-yaml extension, you can add the "yaml.schemas" setting, specifying a specific YAML schema (via URL, which can be local or remote) for a set of files defined using regular expressions. For simplicity, let's assume we placed our YAML schema directly in the .vscode folder.

<img width="1600" height="203" alt="step2" src="https://github.com/user-attachments/assets/a0c2304f-6e38-4195-ab73-8bbdf23d9149" />

## Step 3
Next, we need to obtain this schema. When this patch is merged, this can be done using the `--dump-yaml-schema` option.

<img width="803" height="419" alt="step3" src="https://github.com/user-attachments/assets/faaad1f5-3502-49b2-a480-8a54b23bdb4e" />

After that, copy it to the clipboard.

## Step 4
Now, copy it to a file, and optionally add fields for the "title" and the "$schema" format that this schema itself conforms to.

<img width="1117" height="690" alt="step4" src="https://github.com/user-attachments/assets/932a3ff5-10aa-44b0-997e-8914bebadd5c" />

## Step 5
So, now everything is ready, and you can enter the input configuration. To see the current suggestions from the IDE, press Ctrl+Space. At the top of the input file, you will see the name of the specified YAML schema (if added).

<img width="1323" height="380" alt="step5" src="https://github.com/user-attachments/assets/1fb77f2c-8171-45c8-bf47-0eb09c365642" />

This is how the proposed functionality is expected to be used in such a straightforward way.


https://github.com/llvm/llvm-project/pull/164412


More information about the llvm-commits mailing list