chore: add clang-tidy pre-commit hook#571
Open
Mordris wants to merge 2 commits into
Open
Conversation
Run the same clang-tidy static analysis as CI locally before pushing. scripts/run_clang_tidy.py analyses only the changed C/C++ files present in build/compile_commands.json, using the repo .clang-tidy config and --warnings-as-errors=*, matching .github/workflows/clang_tidy.yml. When clang-tidy or the compilation database is unavailable the hook skips with a hint instead of blocking the commit, so a configured build is not required to commit; set ZVEC_CLANG_TIDY_STRICT=1 to make missing tooling an error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #294.
What changed
clang-tidyhook to.pre-commit-config.yamlso the CI clang-tidy check can be run locally before pushing.scripts/run_clang_tidy.py, which the hook calls. It mirrors.github/workflows/clang_tidy.yml: only the changed C/C++ files that appear inbuild/compile_commands.jsonare analysed, using the repo.clang-tidyconfig and--warnings-as-errors=*.thirdparty/,build/, or the generatedgen/dirs — are skipped, matching the workflow's ignore list.ZVEC_CLANG_TIDY_STRICT=1to make missing tooling an error;CLANG_TIDY/BUILD_DIRoverride the binary and build directory.How to use
cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON pre-commit installThe hook then runs on the C/C++ files you change; commit as usual.
Validation
pre-commit validate-configpasses;scripts/run_clang_tidy.pypasses the reporufflint and format checks.cmake -S . -B build -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DBUILD_TOOLS=ON; compilation database with ~1.6k entries; clang-tidy 18.1.1), driven throughpre-commit run clang-tidy:src/ailego/) pass;modernize-use-nullptrviolation temporarily added to a tracked source file makes the hook fail (exit 1) with the diagnostic, and passes again once reverted;thirdparty/and generatedgen/dirs, and files absent from the compilation database, are skipped;build/compile_commands.jsonthe hook skips without blocking the commit (and fails underZVEC_CLANG_TIDY_STRICT=1).