For those of you that regularly use clang-tidy as part of your workflow, I was curious as to how you use it. Trying to learn what the typical best practices are.
Do you run it as part of your regular build cycle? Just on PR requests or merge hooks? Just ad hoc?
Did you write your own clang-tidy checks? If so, do you actually submit them to llvm or just run them on your own?
I use clang-tidy with run-clang-tidy.py, and run it from CI so that pull requests are verified:
-
https://github.com/Sarcasm/irony-mode/blob/82ba45ec15c9011bbdf1d69cf25c8193d33c0028/server/.clang-tidy
I run it on Travis CI, see configuration here:
-
https://github.com/Sarcasm/irony-mode/blob/82ba45ec15c9011bbdf1d69cf25c8193d33c0028/.travis.yml#L49-L54
For the PR to get validated, I treat warnings as errors:
-
https://github.com/Sarcasm/irony-mode/tree/82ba45ec15c9011bbdf1d69cf25c8193d33c0028/server/build-aux/run-clang-tidy
I have a similar setup for clang-format:
-
https://github.com/Sarcasm/run-clang-format
I also have some notes about clang-tidy, which I will update soon now that I have started using it at work:
-
https://sarcasm.github.io/notes/dev/clang-tidy.html
It's part of my CMake file. See eg. this.
How to use .clang-tidy config file?
c++ - How to use and configure clang-tidy on windows? - Stack Overflow
How to use Clang tidy in CMake - Stack Overflow
How to activate clang-tidy checks
How do I enable clang-tidy in Visual Studio?
What is the difference between clang-tidy and compiler warnings?
How can I ignore specific clang-tidy warnings?
Videos
» pip install clang-tidy
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.
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:
set_target_properties(MyTarget PROPERTIES
VS_GLOBAL_RunCodeAnalysis false
# Use visual studio core guidelines
VS_GLOBAL_EnableMicrosoftCodeAnalysis false
#VS_GLOBAL_CodeAnalysisRuleSet ${CMAKE_CURRENT_SOURCE_DIR}/foo.ruleset
#VS_GLOBAL_CodeAnalysisRuleSet ${CMAKE_CURRENT_SOURCE_DIR}/foo.ruleset
# Use clangtidy
VS_GLOBAL_EnableClangTidyCodeAnalysis true
VS_GLOBAL_ClangTidyChecks "-* \"\"--config-file=${MY_CLANG_TIDY_CONFIG_PATH} --header-filter=.*"
)