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:
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?
2
Answers
It seems Visual Studio may invoke clang-tidy from a directory outside the source tree in cases where the build is generated out-of-source (as commonly happens when using CMake).
I found a small hack around it. Basically I trick Visual Studio into thinking I am giving it a list of checks, where in fact I give it the path to the config file along with whatever arguments I want. (note the extra
"
characters).This is of course a hack. But still might serve somebody.
Here is a way to do that with CMake:
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.