fix(hooks): scope pre-commit clang-tidy to staged changes (#1264) - #1310
Open
Yyunozor wants to merge 1 commit into
Open
fix(hooks): scope pre-commit clang-tidy to staged changes (#1264)#1310Yyunozor wants to merge 1 commit into
Yyunozor wants to merge 1 commit into
Conversation
) make -j3 -f Makefile.cbm lint runs the full lint-tidy sweep, which currently surfaces ~5,100 pre-existing clang-tidy findings across 113 files. Since the pre-commit hook (scripts/hooks/pre-commit) runs that target unconditionally, it blocks every commit for every contributor who has clang-tidy on PATH, regardless of what the commit touches. Add lint-tidy-diff (scripts/lint-tidy-diff.sh), which runs the same clang-tidy binary/config but passes clang-tidy's own -line-filter so only lines the commit actually added or modified can produce a diagnostic. Pre-existing findings on untouched lines are not reported, whether they are in an untouched file or on an untouched line of a file the commit does touch. The hook now runs lint-ci (unchanged: cppcheck + clang-format + no-suppress) plus lint-tidy-diff instead of the full lint target; make lint / make lint-tidy / scripts/lint.sh are unchanged and remain the full-tree audit. Signed-off-by: Yyunozor <yyunozor@icloud.com>
Yyunozor
force-pushed
the
fix/1264-hook-diff-aware-clang-tidy
branch
from
July 28, 2026 16:33
4590016 to
ca796df
Compare
Owner
|
Thank you for the contribution and for reproducing how repository-wide clang-tidy findings block unrelated staged changes. This is now triaged as a normal-priority contributor-workflow bug for |
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.
Fixes #1264
Problem
scripts/hooks/pre-commitrunsmake -j3 -f Makefile.cbm lintunconditionally on every commit.
lintincludeslint-tidy, which runsclang-tidy over the whole
LINT_SRCStree. On a cleanmaincheckoutthat surfaces ~5,100 pre-existing
error:-level findings across 113files (mostly
readability-magic-numbers), unrelated to whatever thecommit touches. The hook blocks every commit for every contributor with
clang-tidy on
PATH— reproduced on a clean checkout, one-line non-Cchange.
Fix
Add
lint-tidy-diff(scripts/lint-tidy-diff.sh), a Makefile targetrunning the same clang-tidy binary/config, but passing clang-tidy's own
-line-filterso a diagnostic can only fire on lines the commit actuallyadded or modified (parsed from
git diff --cached -U0hunk headers).Pre-existing findings on untouched lines are never reported, whether in
an untouched file or an untouched line of a touched file — baseline-aware
at the line level, not just the file level.
The hook now runs
lint-ci(unchanged: cppcheck + clang-format +no-suppress, already CI's contract) plus
lint-tidy-diffinstead of thefull
linttarget.make lint,make lint-tidy, andscripts/lint.share untouched, still the full-tree audit; CI (
_lint.yml→scripts/lint.sh --ci) never ran clang-tidy and is unaffected. Thisfollows the scoping the issue itself suggested (remediation option 2), at
line rather than file granularity.
Verification
git commit -son a one-lineCONTRIBUTING.mdchange, clang-tidy onPATH→ blocked, 5,190pre-existing findings, commit did not happen.
.cchanges → skipped, exit 0.internal/cbm/cbm.c(one of the dirtiest files, 57pre-existing findings on a full-file run of the same edit) → exit 0,
nothing reported.
return 424242;) added to the same file →exit 2, reports only that one finding.
.cchange) → skipped, exit 0 (seeKnown limitation).
scripts/lint.sh(cppcheck + clang-format + no-suppress) unaffected,still clean.
Known limitation
clang-tidy reports a header's diagnostics under whatever path it was
#include-d with, not reliably its working-tree path (verified:absolute vs. search-path-relative, depending on include style). So
lint-tidy-diffscopes.cfiles only; a header-only commit isn'tcovered and needs
make lint-tidy. A proper diff-to-header mapping wouldbe a natural follow-up, left for the maintainer to size.