Skip to content

Commit 2bf26aa

Browse files
authored
Merge pull request #4948 from sinemakinci1/main
Update clang-tidy.md
2 parents 533991f + 474bf33 commit 2bf26aa

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

docs/code-quality/clang-tidy.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,58 @@ 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+
Clang-Tidy recognizes the following keys:
3537

3638
- `enableMicrosoftCodeAnalysis`: Enables Microsoft Code Analysis
3739
- `enableClangTidyCodeAnalysis`: Enables Clang-Tidy analysis
38-
- `clangTidyChecks`: Clang-Tidy configuration, specified as a comma-separated list, that is, checks to be enabled or disabled
40+
- `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`.
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+
46+
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.
47+
48+
An example CMake settings implementation looks like this:
49+
50+
```json
51+
{
52+
"configurations": [
53+
{
54+
"name": "x64-debug",
55+
"generator": "Ninja",
56+
....
57+
"clangTidyChecks": "llvm-include-order, -modernize-use-override",
58+
"enableMicrosoftCodeAnalysis": true,
59+
"enableClangTidyCodeAnalysis": true
60+
}
61+
]
62+
}
63+
```
64+
65+
### CMake presets
66+
67+
The same keys can be used in your CMake presets via the `vendor` object.
68+
69+
An example CMake preset implementation looks like this:
70+
71+
```json
72+
"configurePreset": [
73+
{ "name": "base",
74+
....
75+
"vendor": {
76+
"microsoft.com/VisualStudioSettings/CMake/1.0": {
77+
"clangTidyChecks": "llvm-include-order, -modernize-use-override",
78+
"enableMicrosoftCodeAnalysis": true,
79+
"enableClangTidyCodeAnalysis": true
80+
}
81+
}
82+
}
83+
]
84+
```
85+
4286
## Warning display
4387

4488
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)