hk 2.14.0 lets secret scanners check every commit in a push. It adds an opt-in recheck_after_fix setting so a check runs again when a later fixer changes its files, and it adds the bun_fmt, keep_sorted, cspell, cspell_commit_message and hk_validate builtins. It also fixes bugs in stash handling, --mise launchers and stdin formatters.
Added
-
Scan every pushed commit for secrets (#1880, @jdx). Before, a scanner on
pre-pushonly checked the final state of the files. A credential added in one commit and removed in a later one passed, even though the push still sent the first commit.gitleaks,betterleaks,trufflehogandkingfishernow acceptscan = "commits", which scans each commit in the run's ref range (pre-push,--from-refor--pr):hooks { ["pre-push"] { steps { ["gitleaks"] = (Builtins.gitleaks) { scan = "commits" } } } }
The default
scanfor each builtin is unchanged. This change also adds arequires_ref_rangestep field. When a step sets it and the run has no ref range, the step fails with an error such asgitleaks: needs a ref range (pre-push, --from-ref, or --pr)instead of scanning nothing and passing. Step tests can now setfrom_refandto_ref. -
scan = "staged"forbetterleaks(#1878, @jdx). This option works like the one ongitleaks. It runsbetterleaks git --pre-commit --stagedon the index, so a partially staged file is checked as it will be committed. It ignores hk's file selection, so use it inpre-commitrather than withhk check --all. The default (scan = "files") is unchanged. -
recheck_after_fixsetting (#1891, @jdx). Steps in a fix run (hk fix, or apre-commithook withfix = true) run in parallel. A check could pass on a file before another step's fixer rewrote it, and nothing checked the new contents. With this setting on, hk runs such a check again after all steps finish if a fixer changed the contents of a file the check had passed on. The run fails if the new contents no longer pass. Turn it on with any of these:recheck_after_fix = trueinhk.pklor~/.hkrc.pklHK_RECHECK_AFTER_FIX=1git config hk.recheckAfterFix true
The setting is off by default because it adds file reads to every fix run. Each check runs at most once more, and the second runs keep the original group order,
dependsandexclusive. Steps withcheck_firstare not rerun.hk checkis unaffected. -
New builtins:
bun_fmtruns Bun's built-in formatter forhk check,hk fixandhk check --diff. It passes--no-scriptso afmtscript inpackage.jsoncan't replace the formatter. hk detects it frombunfig.toml,bun.lockorbun.lockb(#1870, @jdx).keep_sortedchecks and sorts the lines betweenkeep-sorted startandkeep-sorted endmarkers (#1898, @jdx).cspellspell-checks text files and follows the project's cspell config. It has no fixer (#1898, @jdx).cspell_commit_messagespell-checks the message in acommit-msghook. It skips git's comment lines and, withgit commit --verbose, the diff below the scissors line (#1898, @jdx).hk_validaterunshk validate --deny-warningswhenhk.pklor.config/hk.pklchanges, so config warnings fail the hook (#1862, @jdx).
hooks { ["pre-commit"] { fix = true steps { ["keep-sorted"] = Builtins.keep_sorted ["cspell"] = Builtins.cspell ["hk_validate"] = Builtins.hk_validate } } ["commit-msg"] { steps { ["cspell"] = Builtins.cspell_commit_message } } }
Changed
ox_lintreports diagnostics (#1871, @jdx). The check command now runsoxlint --deny-warnings --format sarif, so oxlint findings appear inhk check --sarifand JSON output. As a result, a failingox_lintcheck now prints SARIF JSON instead of oxlint's human-readable report.fixis unchanged.to_refdefaults toHEAD(#1880, @jdx). When only--from-refis given,{{to_ref}}andHK_TO_REFare nowHEADinstead of empty.
Fixed
- Stash recovery no longer stalls behind a nested hk (#1852, @jdx). After an interrupted run, recovering a stash that contained untracked files triggered
post-checkout. Ifpost-checkoutran hk, that second hk waited on the stash lock untilHK_STASH_LOCK_TIMEOUT(300 s by default) before the commit could go through. The nested hk now skips its own recovery check. - Stash restore no longer starts a nested hk (#1869, @jdx). With
stash = "git", restoring an untracked file ranpost-checkout, which started a second hk inside the stash window. hk now setsHK=0for that restore. Hooks that aren't managed by hk still run. - Intent-to-add files stay out of commits with
stash = "none"(#1884, @jdx). With the default libgit2 backend, files marked withgit add -Nwere treated as staged. Steps received them in{{files}}, and changes a fixer made to them were committed. hk now leaves them out, as git does and as hk already did withstash = "git"orHK_LIBGIT2=0. --miselaunchers work without mise onPATH. Git clients that start with a minimalPATH, such as GUIs, IDEs and agent shells, could fail withmise: command not found:- The global
hk install --global --miselauncher now adds mise's directory to the end ofPATH, so steps that callmise run ...work (#1875, @jdx). - The per-repo
hk install --miselauncher now records mise's absolute path at install time and adds the samePATHentry, for both config hooks and--legacyshims (#1883, @jdx). Runhk install --miseagain to update existing hooks. mise must be onPATHwhile you run the install.
- The global
- Empty files stay empty with stdin formatters (#1874, @jdx).
hk fixwithtofu(and other builtins that format throughhk util format-diff, such asterraform) wrote a newline into intentionally empty files. hk now treats an empty file as unchanged when the formatter outputs only whitespace for it. GIT_WORK_TREEis set only for steps withdir(#1889, @jdx). Before, every hook step receivedGIT_WORK_TREE. A step that rangit initelsewhere could then writecore.worktreeinto the repository's config. In a linked worktree, that config is shared, so the main checkout was silently repointed. Steps withoutdirnow see the same environment as a plain git hook. The new "Git environment variables in steps" docs section covers the remainingGIT_DIRpitfall.
Security
Full Changelog: v2.13.0...v2.14.0
💚 Sponsor hk
hk is built and maintained by @jdx, an open source developer at entire.io, the title sponsor of his open source work.
If hk speeds up your pre-commit loop or makes linting less painful, please consider becoming an individual or company sponsor. Your support funds ongoing development and helps keep hk fast, free, and independent.