Repository navigation
perf(bash-format): lint each distinct staged file once in shell-check - #16659
Conversation
The pre-commit entry ran ShellCheck on every staged shell path, so a commit that changes 21 byte-identical copies of the 5,174-line hook-utils.sh linted the same bytes 21 times, about 1.8 s each. shell-check.sh now groups the paths it lints by the bytes ShellCheck reads (git hash-object --no-filters), the extension and the nearest .shellcheckrc, lints each group once from its first path, and copies that path's findings to every other member before the changed-line filter, so each copy's own added lines still decide what blocks. A group spread over directories stays whole only when a probe (no rc, no SHELLCHECK_OPTS, directives neutralised) finds no source statement and no error; otherwise it splits by directory, since a SCRIPTDIR search path resolves a sourced file from each script's directory. Any failure while grouping lints every path, as before; a failure copying the findings fails the commit. The batching fixtures in shell-check.test.sh now hold distinct bytes, since identical ones are now linted once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
claude-security-review reviewed Security review: PR #16659, perf(bash-format): lint each distinct staged file onceNo security issues found. I read every hunk of all 3 changed files: the changelog fragment, What I checked in the new grouping code in
Spend: none (a local pre-commit hook; no lane, model or schedule changes). This is the first review of this PR, not blocking only. No prior findings or settled threads apply. critical-findings: 0 |
|
claude-review reviewed Code review: no findingsWhat changed. What I checked (by reading the code; I had no shell, so I ran nothing):
The PR's timing and test results are the author's claims; I did not verify them. Closing issue: none. The PR context says it closes no issue, so there are no acceptance criteria to check. Manifests: no No changed file matches a trusted-path glob, the PR context contains no embedded instructions, and this is the first review of this pull request (blocking only: no). Verifier dropped 0 of 0 candidates. |
Post-merge mutation testingKilled 3, survived 4, timeout 0, no coverage 0, invalid 0, not run 0.
Surviving mutants
The run's summary has the full report. |
No related issue: a measured speed defect in the bash-format pre-commit entry, found while timing the repository's git hooks.
Summary
bash-format's pre-commit entry
plugins/bash-format/git-hooks/shell-check.shran ShellCheck on every staged shell path. Commit83fb17c179changes 21 byte-identical copies of the 5,174-linehook-utils.sh(plugins/*/hooks/hook-utils.sh;lib/hook-utils.shitself is a different blob), and ShellCheck spends about 1.8 s on each copy (shellcheck -x -f gcc -S warning plugins/animation/hooks/hook-utils.sh: 1.76 s). A trace of the entry on that commit put 53.2 s of a 54.5 s run in the one ShellCheck call.The entry now lints each distinct script once and copies the findings to every path that shares it. On that commit the median falls from 56.9 s to 25.7 s; the 1-file and 10-file samples are unchanged.
Fix
Grouping, in
shell-check.shonly (no change to the syncedcheck-lib.sh):git hash-object --no-filters --stdin-paths, so it holds for--worktreemode and for untracked files, and an autocrlf host hashes the bytes on disk), plus the extension, plus the directory of the nearest.shellcheckrc/shellcheckrcat or above the script, up to the top level.shellcheck --norc -s bash -S infoon the script's text with every# shellcheckdirective neutralised andSHELLCHECK_OPTSunset. AnySC1090/SC1091, anyerror(a parse error can hide a latersource), or an exit above 1 splits the group by directory.checks_tool_failed, so findings are never silently dropped.Dedupe rule and its Basis. Two paths are linted once only when they hold the same bytes, the same extension and the same nearest rc, and when they are in different directories, the probe finds nothing they source. Basis: the ShellCheck manual (https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md, read this session) names the inputs that depend on the path:
.shellcheckrcorshellcheckrcin the script's directory and each parent directory";source-path: "The special pathSCRIPTDIRcan be used to specify the currently checked script's directory";shelldirective, shebang, or.bash/.bats/.dash/.kshextension".Paths with the same nearest rc share the whole rc chain above it, so the key stays correct whether ShellCheck reads one rc or merges several. This repository's own
.shellcheckrcsetssource-path=SCRIPTDIR, which is why directory matters for scripts that source. I checked that it can change the result: identicalsource helper.shscripts inx/andy/under that rc lint differently (y/a.sh:3:7: warning: v is referenced but not assigned. [SC2154], nothing forx/a.sh).Verification
Timing.
hyperfine -N --warmup 1 --runs 10on Linux WSL2 (24 CPUs, load average about 4). Each sample commit was staged on its parent in a throwaway worktree. Before meansorigin/mainat3ad9535c79; after means this branch. The two ran back to back on the same tree state.83fb17c179dedc4fd99055c8ce6feaThe 10-file and 1-file differences are within one standard deviation. The 98.9 s figure in the timing table on #16645 came from a different measurement session. In this session one unbenchmarked baseline run took 104.8 s and a traced run 54.5 s, so this host's wall time varies with load. The before and after above were measured together.
The 44-file sample is still above the 10 s commit budget (
docs/contracts/check-placement/README.md, "Duration budgets"). The remaining time goes to distinct files, measured one at a time:lib/hook-utils.test.sh13.4 s andplugins/guardrails/hooks/block-root-delete-target.sh10.1 s (each follows a sourcedhook-utils.shunder-x), pluslib/hook-utils.sh1.8 s, the deduplicated copy 1.8 s, and its probe about 2 s.Tests. I added these to
plugins/bash-format/git-hooks/shell-check.test.shfirst and confirmed that 2 of them failed on the old entry:.shellcheckrcis linted apart, and its rc'sdisableholds;source helper.shundersource-path=SCRIPTDIRare linted apart, and only the copy whose helper leaves the variable unset reports;sourceline and adisable=SC1091directive are linted apart.The batching fixtures (250 long paths,
a-finding.sh,z-finding.sh,a-broken.sh) held identical bytes. They now hold distinct bytes so they keep testing batching rather than grouping. Their expectations are unchanged.Results:
bash plugins/bash-format/git-hooks/shell-check.test.sh: 82 passed, 0 failed.bash plugins/bash-format/hooks/bash-format.test.sh: 38 passed, 2 failed.bash plugins/bash-format/hooks/bash-format-end-of-turn.test.sh: 7 passed, 2 failed.origin/mainin this environment: "shfmt absent", "a missing shellcheck passes silently" and the two "spawn budget" cases. This change does not touch those files.shellcheck -x --rcfile .shellcheckrcon both changed shell files: clean.shfmt -ln bash -i 2 -d: clean.scripts/validate-plugins.sh --only bash-format: passed.Related
bash-format shell-check (pre-commit), 83fb17c179, 44 files: 56.9 s before, 25.7 s after (median of 10, hyperfine, Linux WSL2 24 CPUs), plus the 1-file and 10-file rows above.plugins/bash-format/lib/git-hooks/install.mjs), so no committed stamp or synced copy changes. The changelog fragment is.changes/bash-format/perf-shell-check-dedupe-identical-blobs-66766b51.md.🤖 Generated with Claude Code