From 7e466932a8730943f58e8b73b3e0e81198b7b4ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Davorin=20=C3=81cs?= Date: Wed, 14 Feb 2024 11:28:12 +0100 Subject: [PATCH 1/2] Update usage commit The previous version still had an issue whereas the user would get: "The repository '@@com_github_bazelbuild_buildtools' could not be resolved: Repository '@@com_github_bazelbuild_buildtools' is not defined. and referenced by '@@bazel_clang_tidy//clang_tidy:clang_tidy'" --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f990882..e4f3090 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ load( git_repository( name = "bazel_clang_tidy", - commit = "69aa13e6d7cf102df70921c66be15d4592251e56", + commit = "43bef6852a433f3b2a6b001daecc8bc91d791b92", remote = "https://github.com/erenon/bazel_clang_tidy.git", ) ``` From e11873cf6e96efb94051c3a96a59372a1accfced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Davorin=20=C3=81cs?= Date: Wed, 14 Feb 2024 11:34:34 +0100 Subject: [PATCH 2/2] Fix minor markdown omissions Added types to fenced blocks, that were missing it. Replaced code block by indentation with regular fenced block. Replaced numbered list usage to use only 1s instead of hard-coded values. This makes it easier to add/remove list elements as markdown will handle the number increment internally during list rendering. --- README.md | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e4f3090..0584f75 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ git_repository( You can now compile using the default clang tidy configuration provided using the following command; -``` +```text bazel build //... \ --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect \ --output_groups=report @@ -55,11 +55,10 @@ bazel build //... \ :exclamation: 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 you add a config in your .bazelrc that matches this command line; -``` +```text # Required for bazel_clang_tidy to operate as expected build:clang-tidy --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect build:clang-tidy --output_groups=report @@ -75,9 +74,11 @@ 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: -``` + +```text build:clang-tidy --@bazel_clang_tidy//:clang_tidy_executable=@local_config_cc//:clangtidy_bin ``` @@ -99,18 +100,22 @@ Edit `.clang-tidy` as needed. To see the tool in action: -1. Clone the repository -2. Run clang-tidy: +1. Clone the repository +1. Run clang-tidy: - bazel build //example --aspects clang_tidy/clang_tidy.bzl%clang_tidy_aspect --output_groups=report + ```sh + bazel build //example --aspects clang_tidy/clang_tidy.bzl%clang_tidy_aspect --output_groups=report + ``` -3. Check the error: +1. Check the error: - 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 + ```text + 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 + ``` -4. Fix the error by changing `lib.cpp` only. -5. Re-run clang-tidy with the same command. Observe that it does not run clang-tidy for `app.cpp`: the cached report is re-used. +1. Fix the error by changing `lib.cpp` only. +1. Re-run clang-tidy with the same command. Observe that it does not run clang-tidy for `app.cpp`: the cached report is re-used. ## Requirements