I'm trying to apply clang modernization on files either from within visual studio, or from the command line, making use of the includes paths and settings in my visual studio 2015 C++ projects.
I created a clang-tidy settings file, like this:
clang-tidy -dump-config=.clang-tidy
-checks="modernize-loop-convert,modernize-deprecated-headers"
and verified that it works on a single file, from (cygwin) command line: clang-tidy.exe -explain-config
lists (among other things)
'modernize-deprecated-headers' is enabled in the C:\abc\.clang-tidy.
and I can run it on individual files by setting up the includes by hand:
clang-tidy.exe someFile.cpp -- -Ic:/abc -I. -IIncludes
I installed the visual studio clang-format VS plugin, and created an example .clang-format file, { BasedOnStyle: "LLVM", IndentWidth: 20 }
which is picked up by the VS plugin. I then naively tried to feed clang-format with the clang-tidy configuration, but unsurprisingly that does not work at all.
To summarize: how to run clang-tidy on files and visual studio projects?
Perhaps a workaround would be to dump out the includes for each file from visual studio? Any way forward will do.
For reference:
How can I enable clang-tidy's "modernize" checks?
How to feed Visual Studio Clang-Format plugin with clang-format file?
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-* .
For Windows projects, Visual Studio by default invokes Clang in clang-cl mode. It links with the Microsoft implementation of the Standard Library.
clang-tidy is a clang-based C++ “linter” tool. Its purpose is to provide an extensible framework for diagnosing and fixing typical programming errors, like style violations, interface misuse, or bugs that can be deduced via static analysis.
Visual Studio 2019 version 16.4+ has native support for clang-tidy
!
I am a Cppcheck developer.
You can run clang-tidy on visual studio solutions in the Cppcheck GUI.
It is a free open source (GPL) tool. You can download it here: http://cppcheck.sf.net
Some screenshots: http://cppcheck.sourceforge.net/clangtidy/index.html
It doesn't currently integrate other clang tools (for instance clang-format) but it is possible to extract the clang-tidy commands used by Cppcheck GUI.. maybe you can edit those.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With