fix(hooks): scope pre-commit clang-tidy to staged changes (#1264) - #1310
fix(hooks): scope pre-commit clang-tidy to staged changes (#1264)#1310Yyunozor 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>
4590016 to
ca796df
Compare
|
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 |
|
A quick note so this does not sit here looking like your problem: neither of your red checks is caused by your change. Your diff touches
A lint-hook and Makefile change cannot cause a daemon-IPC ASan crash. That second one is a production crash in our own code and I have flagged it internally for its own investigation — thank you for surfacing it, entirely by accident. So nothing is needed from you on the CI front; a rebase would pick up the smoke fix, but the ASan crash is ours. Your PR is queued for a proper content review. Apologies for the delay — we are working through a large backlog oldest-first, and I did not want a crash of ours sitting on your PR looking like your bug. |
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.