Skip to content

Commit 0c23813

Browse files
authored
Update clang-tidy.md
Adding support for CMake Presets
1 parent 8b9cc44 commit 0c23813

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

docs/code-quality/clang-tidy.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,51 @@ For more information, see [How to: Set Code Analysis Properties for C/C++ Projec
3131

3232
## CMake
3333

34-
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:
34+
In CMake projects, you can configure Clang-Tidy checks within *`CMakeSettings.json`* or *`CMakePresets.json`*.
35+
36+
The following keys are recognized for clang-tidy:
3537

3638
- `enableMicrosoftCodeAnalysis`: Enables Microsoft Code Analysis
3739
- `enableClangTidyCodeAnalysis`: Enables Clang-Tidy analysis
3840
- `clangTidyChecks`: Clang-Tidy configuration, specified as a comma-separated list, that is, checks to be enabled or disabled
3941

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

44+
### CMake Settings
45+
To edit your clang-tidy settings, open your CMake Settings, select "Edit JSON" in the top right-hand corner of the CMake Project Settings Editor. You can use the keys above to fill out your clang-tidy specifications in the CMake Settings json file.
46+
An example CMake settings implementation would look like this:
47+
```
48+
{
49+
"configurations": [
50+
{
51+
"name": "x64-debug",
52+
"generator": "Ninja",
53+
....
54+
"clangTidyChecks": "",
55+
"enableMicrosoftCodeAnalysis": true,
56+
"enableClangTidyCodeAnalysis": true
57+
}
58+
]
59+
}
60+
```
61+
62+
### CMake Presets
63+
The same keys can be used in your CMake presets via the `vendor` object.
64+
An example CMake preset implementation would look like this:
65+
```"configurePreset": [
66+
{ "name": "base",
67+
....
68+
"vendor": {
69+
"microsoft.com/VisualStudioSettings/CMake/1.0": {
70+
"clangTidyChecks": "",
71+
"enableMicrosoftCodeAnalysis": true,
72+
"enableClangTidyCodeAnalysis": true
73+
}
74+
}
75+
}
76+
]
77+
```
78+
4279
## Warning display
4380

4481
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**.

0 commit comments

Comments
 (0)