{"id":42031731,"url":"https://github.com/erenon/bazel_clang_tidy","last_synced_at":"2026-01-26T04:36:29.306Z","repository":{"id":43042567,"uuid":"255945599","full_name":"erenon/bazel_clang_tidy","owner":"erenon","description":"Run clang-tidy on Bazel C++ targets directly, efficiently, with caching enabled","archived":false,"fork":false,"pushed_at":"2026-01-21T06:55:41.000Z","size":42,"stargazers_count":128,"open_issues_count":23,"forks_count":67,"subscribers_count":2,"default_branch":"master","last_synced_at":"2026-01-21T18:34:24.587Z","etag":null,"topics":["bazel","clang-tidy","cpp"],"latest_commit_sha":null,"homepage":null,"language":"Starlark","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/erenon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-04-15T14:40:30.000Z","updated_at":"2026-01-21T06:55:45.000Z","dependencies_parsed_at":"2023-02-09T14:32:09.947Z","dependency_job_id":"1a8fef15-51a5-4718-a255-554f97b0edca","html_url":"https://github.com/erenon/bazel_clang_tidy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/erenon/bazel_clang_tidy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erenon%2Fbazel_clang_tidy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erenon%2Fbazel_clang_tidy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erenon%2Fbazel_clang_tidy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erenon%2Fbazel_clang_tidy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erenon","download_url":"https://codeload.github.com/erenon/bazel_clang_tidy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erenon%2Fbazel_clang_tidy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28766887,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T03:54:34.369Z","status":"ssl_error","status_checked_at":"2026-01-26T03:54:33.031Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bazel","clang-tidy","cpp"],"created_at":"2026-01-26T04:36:29.235Z","updated_at":"2026-01-26T04:36:29.295Z","avatar_url":"https://github.com/erenon.png","language":"Starlark","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bazel_clang_tidy\n\nRun clang-tidy on Bazel C/C++ targets directly,\nwithout generating a compile commands database,\nand take advantage of Bazels powerful cache mechanism.\n\nUsage:\n\n```py\n# //:WORKSPACE\nload(\n    \"@bazel_tools//tools/build_defs/repo:git.bzl\",\n    \"git_repository\",\n)\n\ngit_repository(\n       name = \"bazel_clang_tidy\",\n       commit = \"bff5c59c843221b05ef0e37cef089ecc9d24e7da\",\n       remote = \"https://github.com/erenon/bazel_clang_tidy.git\",\n)\n```\n\nYou can now compile using the default clang tidy configuration provided using\nthe following command;\n\n```text\nbazel build //... \\\n  --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect \\\n  --output_groups=report\n```\n\nIf you would like to override the default clang tidy configuration then you can\nreconfigure the default target from the command line. To do this you must first\nmake a filegroup target that has the .clang-tidy config file as a data\ndependency.\n\n```py\n# //:BUILD\nfilegroup(\n       name = \"clang_tidy_config\",\n       srcs = [\".clang-tidy\"],\n       visibility = [\"//visibility:public\"],\n)\n```\n\nNow you can override the default config file in this repository using\na command line flag;\n\n```sh\nbazel build //... \\\n  --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect \\\n  --output_groups=report \\\n  --@bazel_clang_tidy//:clang_tidy_config=//:clang_tidy_config\n```\n\n: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.\n\nNow if you don't want to type this out every time, it is recommended that you\nadd a config in your .bazelrc that matches this command line;\n\n```text\n# Required for bazel_clang_tidy to operate as expected\nbuild:clang-tidy --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect\nbuild:clang-tidy --output_groups=report\n\n# Optionally override the .clang-tidy config file target\nbuild:clang-tidy --@bazel_clang_tidy//:clang_tidy_config=//:clang_tidy_config\n```\n\nNow from the command line this is a lot nicer to use;\n\n```sh\nbazel build //... --config clang-tidy\n```\n\n### use a non-system clang-tidy\n\nby default, bazel_clang_tidy uses the system provided clang-tidy.\nIf you have a hermetic build, you can use your own clang-tidy target like this:\n\n```text\nbuild:clang-tidy --@bazel_clang_tidy//:clang_tidy_executable=@local_config_cc//:clangtidy_bin\n```\n\nThis aspect is not executed on external targets. To exclude other targets,\nusers may tag a target with `no-clang-tidy` or `noclangtidy`.\n\n### use with non-system gcc\n\nCreate a label to the installation dir of your gcc toolchain, for example with\nskylib's `directory`.\n\n```py\n# BUILD file for gcc\nload(\"@bazel_skylib//rules/directory:directory.bzl\", \"directory\")\n\npackage(default_visibility = [\"//visibility:public\"])\n\ndirectory(\n    name = \"toolchain_root\",\n    srcs = glob([\n        \"lib/**\",\n        \"x86_64-buildroot-linux-gnu/include/**\",\n    ]),\n)\n\ndirectory(\n    name = \"x86_64-buildroot-linux-gnu\",\n    srcs = [\"lib/gcc/x86_64-buildroot-linux-gnu/13.3.0\"],\n)\n\n```\n\nthen add the toolchain as an additional dependency and set the `clang_tidy_gcc_install_dir` option\n\n```text\nbuild:clang-tidy --@bazel_clang_tidy//:clang_tidy_gcc_install_dir=@gcc-linux-x86_64//:x86_64-buildroot-linux-gnu\nbuild:clang-tidy --@bazel_clang_tidy//:clang_tidy_additional_deps=@gcc-linux-x86_64//:toolchain_root\n```\n\n### use with a vendored clang-tidy\n\nIn the case you vendor clang-tidy, potentially alongside clang itself,\nit's possible clang-tidy cannot automatically find the `-resource-dir`\npath to the builtin headers. In this case, you can use skylib's\n`directory` rule to create a target to the clang resource directory.\n\n```bzl\nload(\"@bazel_skylib//rules/directory:directory.bzl\", \"directory\")\n\ndirectory(\n    name = \"resource_dir\",\n    srcs = glob([\"lib/clang/*/include/**\"]),\n    visibility = [\"//visibility:public\"],\n)\n```\n\nThen pass the `resource_dir` with a flag in your `.bazelrc`:\n\n```\nbuild:clang-tidy --@bazel_clang_tidy//:clang_tidy_resource_dir=//path/to:resource_dir\n```\n\n## Features\n\n- Run clang-tidy on any C/C++ target\n  - A file is treated as C if it has the `.c` extension or its target includes the `clang-tidy-is-c-tu` tag; otherwise, it is treated as C++.\n- Run clang-tidy without also building the target\n- Use Bazel to cache clang-tidy reports: recompute stale reports only\n\n## Install\n\nCopy `.clang-tidy`, `BUILD` and `clang_tidy` dir to your workspace.\nEdit `.clang-tidy` as needed.\n\n## Example\n\nTo see the tool in action:\n\n1. Clone the repository\n1. Run clang-tidy:\n\n    ```sh\n    bazel build //example --aspects clang_tidy/clang_tidy.bzl%clang_tidy_aspect --output_groups=report\n    ```\n\n1. Check the error:\n\n    ```text\n    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)\n    Aspect //clang_tidy:clang_tidy.bzl%clang_tidy_aspect of //example:app failed to build\n    ```\n\n1. Fix the error by changing `lib.cpp` only.\n1. 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.\n\n## Requirements\n\n- Bazel 4.0 or newer (might work with older versions)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferenon%2Fbazel_clang_tidy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferenon%2Fbazel_clang_tidy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferenon%2Fbazel_clang_tidy/lists"}