You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
If you would like to override the default clang tidy configuration then you canreconfigure the default target from the command line. To do this you must firstmake a filegroup target that has the .clang-tidy config file as a datadependency.
❗ the config-file will not be forced by adding it to the clang-tidy command line. Therefore it must be in one of the parents of all source files. It is recommended to put it in the root directly besides the WORKSPACE file.
Now if you don't want to type this out every time, it is recommended that youadd a config in your .bazelrc that matches this command line;
# Required for bazel_clang_tidy to operate as expectedbuild:clang-tidy --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspectbuild:clang-tidy --output_groups=report# Optionally override the .clang-tidy config file targetbuild:clang-tidy --@bazel_clang_tidy//:clang_tidy_config=//:clang_tidy_config
Now from the command line this is a lot nicer to use;
bazel build //... --config clang-tidy
use a non-system clang-tidy
by default, bazel_clang_tidy uses the system provided clang-tidy.If you have a hermetic build, you can use your own clang-tidy target like this:
lib.cpp:4:43: error: the parameter 'name' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param,-warnings-as-errors] std::string lib_get_greet_for(std::string name)Aspect //clang_tidy:clang_tidy.bzl%clang_tidy_aspect of //example:app failed to build
Fix the error by changinglib.cpp only.
Re-run clang-tidy with the same command. Observe that it does not run clang-tidy forapp.cpp: the cached report is re-used.
Requirements
Bazel 4.0 or newer (might work with older versions)
About
Run clang-tidy on Bazel C++ targets directly, efficiently, with caching enabled