Skip to content

chore: Optionally run clang-tidy via pre-commit#6680

Merged
bthomee merged 22 commits intoXRPLF:developfrom
godexsoft:chore/pre-commit-clang-tidy
Apr 22, 2026
Merged

chore: Optionally run clang-tidy via pre-commit#6680
bthomee merged 22 commits intoXRPLF:developfrom
godexsoft:chore/pre-commit-clang-tidy

Conversation

@godexsoft
Copy link
Copy Markdown
Contributor

@godexsoft godexsoft commented Mar 27, 2026

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 tidy env variable (e.g. TIDY=1 git commit ...).
The script then only runs if run-clang-tidy or run-clang-tidy-21 is available in $PATH.
It also attempts to detect your build directory. The common choices are build and .build but 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.

@godexsoft godexsoft requested a review from mathbunnyru March 27, 2026 16:50
Copy link
Copy Markdown
Contributor

@kuznetsss kuznetsss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor suggestions, feel free to ignore

Comment thread bin/pre-commit/clang_tidy_check.py
Comment thread scripts/clang_tidy_check.py Outdated
Comment thread scripts/clang_tidy_check.py Outdated
Copy link
Copy Markdown
Contributor

@mathbunnyru mathbunnyru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor suggestions

Comment thread scripts/clang_tidy_check.py Outdated
Comment thread scripts/clang_tidy_check.py Outdated
Comment thread scripts/clang_tidy_check.py Outdated
Comment thread bin/pre-commit/clang_tidy_check.py
Comment thread bin/pre-commit/clang_tidy_check.py
Comment thread scripts/clang_tidy_check.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py to discover staged files, locate a build dir with compile_commands.json, and run run-clang-tidy (optionally resolving header changes to TUs).
  • Register a new local clang-tidy hook 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.

Comment thread bin/pre-commit/clang_tidy_check.py
Comment thread bin/pre-commit/clang_tidy_check.py
Comment thread .pre-commit-config.yaml Outdated
Comment thread .pre-commit-config.yaml Outdated
godexsoft and others added 2 commits April 1, 2026 18:29
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Ayaz Salikhov <mathbunnyru@users.noreply.github.com>
@mathbunnyru mathbunnyru added the Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required. label Apr 21, 2026
Comment thread scripts/clang_tidy_check.py Outdated
Comment thread scripts/clang_tidy_check.py Outdated
Copy link
Copy Markdown
Collaborator

@bthomee bthomee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copilot AI review requested due to automatic review settings April 21, 2026 22:34
Co-authored-by: Bart <bthomee@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread scripts/clang_tidy_check.py Outdated
Comment thread bin/pre-commit/clang_tidy_check.py
Comment thread bin/pre-commit/clang_tidy_check.py
Comment thread bin/pre-commit/clang_tidy_check.py
Comment thread bin/pre-commit/clang_tidy_check.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 21, 2026 22:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread scripts/clang_tidy_check.py Outdated
Comment thread bin/pre-commit/clang_tidy_check.py
godexsoft and others added 2 commits April 21, 2026 23:53
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 21, 2026 22:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread bin/pre-commit/clang_tidy_check.py
Comment thread bin/pre-commit/clang_tidy_check.py
Comment thread bin/pre-commit/clang_tidy_check.py
Comment thread bin/pre-commit/clang_tidy_check.py
Comment thread bin/pre-commit/clang_tidy_check.py
Copilot AI review requested due to automatic review settings April 21, 2026 23:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .pre-commit-config.yaml
Comment thread CONTRIBUTING.md Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.5%. Comparing base (7c7c189) to head (efa4416).
⚠️ Report is 3 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@            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     

see 2 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 22, 2026 13:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .pre-commit-config.yaml
@bthomee bthomee added this pull request to the merge queue Apr 22, 2026
Merged via the queue into XRPLF:develop with commit 4ab2077 Apr 22, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready to merge *PR author* thinks it's ready to merge. Has passed code review. Perf sign-off may still be required.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants