Skip to content

Update clang-tidy.md #4948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions docs/code-quality/clang-tidy.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,58 @@ For more information, see [How to: Set Code Analysis Properties for C/C++ Projec

## CMake

In CMake projects, you can configure Clang-Tidy checks within *`CMakeSettings.json`*. Once opened, select "Edit JSON" in the top right-hand corner of the CMake Project Settings Editor. The following keys are recognized:
In CMake projects, you can configure Clang-Tidy checks within *`CMakeSettings.json`* or *`CMakePresets.json`*.

Clang-Tidy recognizes the following keys:

- `enableMicrosoftCodeAnalysis`: Enables Microsoft Code Analysis
- `enableClangTidyCodeAnalysis`: Enables Clang-Tidy analysis
- `clangTidyChecks`: Clang-Tidy configuration, specified as a comma-separated list, that is, checks to be enabled or disabled
- `clangTidyChecks`: Clang-Tidy configuration. A comma-separated list of checks to enable or disable. A leading `-` disables the check. For example, "cert-oop58-cpp, -cppcoreguidelines-no-malloc, google-runtime-int" enables `cert-oop58-cpp` and `google-runtime-int`, but disables `cppcoreguidelines-no-malloc`.

If neither of the "enable" options are specified, Visual Studio will select the analysis tool matching the Platform Toolset used.

### CMake settings

To edit your Clang-Tidy settings, open your CMake settings, and select **Edit JSON** in the CMake Project Settings Editor. You can use the keys above to fill out your Clang-Tidy specifications in the CMake Settings json file.

An example CMake settings implementation looks like this:

```json
{
"configurations": [
{
"name": "x64-debug",
"generator": "Ninja",
....
"clangTidyChecks": "llvm-include-order, -modernize-use-override",
"enableMicrosoftCodeAnalysis": true,
"enableClangTidyCodeAnalysis": true
}
]
}
```

### CMake presets

The same keys can be used in your CMake presets via the `vendor` object.

An example CMake preset implementation looks like this:

```json
"configurePreset": [
{ "name": "base",
....
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"clangTidyChecks": "llvm-include-order, -modernize-use-override",
"enableMicrosoftCodeAnalysis": true,
"enableClangTidyCodeAnalysis": true
}
}
}
]
```

## Warning display

Clang-Tidy runs result in warnings displayed in the Error List, and as in-editor squiggles underneath relevant sections of code. Use the "Category" column in the Error List to sort and organize Clang-Tidy warnings. You can configure in-editor warnings by toggling the "Disable Code Analysis Squiggles" setting under **Tools** > **Options**.
Expand Down