clang-tidy
is a tool toautomatically check C/C++/Objective-C code for style violations, programmingerrors, and best practices.
Electron's clang-tidy
integration is provided as a linter script which canbe run with npm run lint:clang-tidy
. While clang-tidy
checks your on-diskfiles, you need to have built Electron so that it knows which compiler flagswere used. There is one required option for the script --output-dir
, whichtells the script which build directory to pull the compilation informationfrom. A typical usage would be:npm run lint:clang-tidy --out-dir ../out/Testing
With no filenames provided, all C/C++/Objective-C files will be checked.You can provide a list of files to be checked by passing the filenames afterthe options:npm run lint:clang-tidy --out-dir ../out/Testing shell/browser/api/electron_api_app.cc
While clang-tidy
has along listof possible checks, in Electron only a few are enabled by default. At themoment Electron doesn't have a .clang-tidy
config, so clang-tidy
willfind the one from Chromium at src/.clang-tidy
and use the checks whichChromium has enabled. You can change which checks are run by using the--checks=
option. This is passed straight through to clang-tidy
, so seeits documentation for full details. Wildcards can be used, and checks canbe disabled by prefixing a -
. By default any checks listed are added tothose in .clang-tidy
, so if you'd like to limit the checks to specificones you should first exclude all checks then add back what you want, like--checks=-*,performance*
.
Running clang-tidy
is rather slow - internally it compiles each file andthen runs the checks so it will always be some factor slower than compilation.While you can use parallel runs to speed it up using the --jobs|-j
option,clang-tidy
also uses a lot of memory during its checks, so it can easilyrun into out-of-memory errors. As such the default number of jobs is one.