chore: Optionally run clang-tidy via pre-commit#6680
Conversation
kuznetsss
left a comment
There was a problem hiding this comment.
A few minor suggestions, feel free to ignore
mathbunnyru
left a comment
There was a problem hiding this comment.
A few minor suggestions
This reverts commit c60cf15.
There was a problem hiding this comment.
Pull request overview
Adds an optional clang-tidy pre-commit hook to streamline running run-clang-tidy locally on staged C/C++ changes (including mapping header edits to a representative translation unit via compile_commands.json).
Changes:
- Add
scripts/clang_tidy_check.pyto discover staged files, locate a build dir withcompile_commands.json, and runrun-clang-tidy(optionally resolving header changes to TUs). - Register a new local
clang-tidyhook in.pre-commit-config.yaml, gated behind an environment variable.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| scripts/clang_tidy_check.py | New pre-commit helper script to run run-clang-tidy on staged sources and resolve header-only changes to compilation units. |
| .pre-commit-config.yaml | Adds a local clang-tidy hook entry (system language) to invoke the new script when enabled. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Ayaz Salikhov <mathbunnyru@users.noreply.github.com>
bthomee
left a comment
There was a problem hiding this comment.
What this script runs is different from what the clang-tidy workflow runs, so it's inevitable that there's going to be a mismatch in formatting. I would suggest that the CI workflow runs this script too.
Also, please don't introduce yet another top-level folder. The vast majority of scripts are in the .github/scripts/ directory, where this one also belongs (after making the change suggested above). There are also scripts in bin/, but those don't seem to be used much and can either be removed or also added to the .github/scripts directory.
Co-authored-by: Bart <bthomee@users.noreply.github.com>
Co-authored-by: Bart <bthomee@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #6680 +/- ##
=========================================
- Coverage 82.5% 82.5% -0.0%
=========================================
Files 1010 1010
Lines 79246 79245 -1
Branches 7529 7529
=========================================
- Hits 65389 65385 -4
- Misses 13857 13860 +3 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
High Level Overview of Change
As the list of enabled clang-tidy checks grows it's becoming more and more important to easily run clang-tidy locally before pushing a change to the repo. This PR makes it a bit more streamlined. There may be some issues with it that we will have to iron out but it's hard to tell what they are until we try to use it on multiple environments.
Overall clang-tidy is too expensive to always run on pre-commit so it ONLY runs if you set the
tidyenv variable (e.g.TIDY=1 git commit ...).The script then only runs if
run-clang-tidyorrun-clang-tidy-21is available in $PATH.It also attempts to detect your build directory. The common choices are
buildand.buildbut could be extended further.WIP: Documentation and more testing needed
Another thing that would be great to figure out is how we can detect .cpp files that depend on headers we may have changed in the commit. clang-tidy does nothing if you pass it just the header.
API Impact
No impact.