Set up clang-tidy static analysis
Table of Contents
This page is a capture in the inbox bucket of the product backlog — a pre-sprint idea, not yet pulled into a sprint as a story.
What
Add clang-tidy to the build infrastructure as a complement to
clang-format. Unlike clang-format (which only cares about layout),
clang-tidy performs semantic static analysis: detecting bugs, flagging
anti-patterns, and suggesting modern C++ idioms. The story would
produce: a .clang-tidy config with a curated check set, CMake
tidy and check-tidy targets backed by run-clang-tidy.py
(from the LLVM toolchain), and a nightly GH Actions workflow that
raises a PR when new violations appear.
Why
clang-format keeps the code consistently laid out; clang-tidy keeps
it consistently correct and modern. Together they form a lightweight
quality baseline that catches issues before code review. The
infrastructure (compile_commands.json from CMake,
FindClangTools.cmake now updated) is already in place.
The check set needs careful curation — enabling everything produces
thousands of false positives. A minimal starting set might be:
modernize-*, readability-*, bugprone-*, clang-analyzer-*,
with per-file suppressions for generated code.
References
build/cmake/modules/FindClangTools.cmake— already updated to find clang-tidy 20 down to 5.0.CMakeLists.txt—CLANG_TIDY_FOUND/CLANG_TIDY_BINalready detected; just needs the targets.- clang-tidy docs: https://clang.llvm.org/extra/clang-tidy/
See also
- Introduce clang-tidy and Lizard via PR-delta ratchet strategy — how to introduce clang-tidy safely into a large legacy codebase: delta-only enforcement, Lizard integration, and three-phase rollout.