Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use clang-tidy modernize with visual studio

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?

like image 654
Johan Lundberg Avatar asked Jan 03 '17 10:01

Johan Lundberg


People also ask

How do I enable clang tidy in Visual Studio?

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-* .

Does Visual Studio use clang?

For Windows projects, Visual Studio by default invokes Clang in clang-cl mode. It links with the Microsoft implementation of the Standard Library.

How does clang tidy work?

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.


2 Answers

Visual Studio 2019 version 16.4+ has native support for clang-tidy!

like image 115
Michel de Ruiter Avatar answered Sep 22 '22 15:09

Michel de Ruiter


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.

like image 21
Daniel Marjamäki Avatar answered Sep 19 '22 15:09

Daniel Marjamäki