The tool clang-tidy checks code against a vast set of rules, and suggests improvements. In a complex project, however, it is prohibitively difficult to run clang-tidy directly from the command line, since it needs include paths and other options just like a regular compilation command needs. Therefore, it is necessary to run clang-tidy through cmake && make
. This can indeed be done, using set(CMAKE_CXX_CLANG_TIDY "clang-tidy")
.
With option –fix, clang-tidy can directly correct the sources. Or with option –export-fixes=, it can write suggested fixes in compact form to a YAML file. Again, it is hopeless to do this directly from the command line; we need CMake support. So I attempted set(CMAKE_CXX_CLANG_TIDY "clang-tidy --export-fixes=out.yml")
. This failed miserably: Error running 'clang-tidy --export-fixe=out.yml ': No such file or directory
.
What’s going wrong? Any workaround?