Search code examples
c++visual-studiocmakeclang-tidy

How to get Visual Studio use a .clang-tidy configuration file when invoking clang-tidy?


Visual Studio (Desktop) has a clang-tidy integration. you can make VS invoke clang-tidy with a list of checks. however, I could not find a way to make it use an existing .clang-tidy configuration file.

The documentation hints that it is possible:

Clang-Tidy configuration By default, Clang-Tidy does not set any checks when enabled. To see the list of checks in the command-line version, run clang-tidy -list-checks in a developer command prompt. You can configure the checks that Clang-Tidy runs inside Visual Studio. In the project Property Pages dialog, open the Configuration Properties > Code Analysis > Clang-Tidy page. Enter checks to run in the Clang-Tidy Checks property. A good default set is clang-analyzer-*. This property value is provided to the --checks argument of the tool. Any further configuration can be included in custom .clang-tidy files. For more information, see the Clang-Tidy documentation on LLVM.org.

This is what I tried to do manually via the VS property pages:

enter image description here

But when running analyses on a file, it doesn't work.

So How to get Visual Studio use a .clang-tidy configuration file when invoking clang-tidy?


Solution

  • The property pages are for setting clang-tidy checks directly (not a path to the .clang-tidy file). Visual Studio should automatically detect the .clang-tidy file in your workspace, as long as it's in the same or a parent folder of your source files.