Skip to content

fix(hooks): run typos at the pre-commit stage only - #1493

Merged
c-vigo merged 2 commits into
devfrom
bugfix/1489-typos-pre-commit-stage
Aug 13, 2026
Merged

c-vigo merged 2 commits into
devfrom
bugfix/1489-typos-pre-commit-stage

Conversation

@c-vigo

@c-vigo c-vigo commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Closes #1489

Problem

The typos hook carried no stages:, so it ran at every hook stage — and
because it has pass_filenames: true, the commit-msg round handed it
COMMIT_EDITMSG. typos reads short letter runs inside abbreviated git SHAs as
misspelled words, and git rebase --continue writes the rebase todo into that
buffer as comment lines, so a legitimate rebase was refused over a comment
that never enters the commit message
. The content being committed is
irrelevant.

The workarounds it invites are editing git's own todo comment or --no-verify,
which this repo forbids.

Change

stages: [pre-commit] on the yaml fragment in nix/hooks.nix, which renders
both committed configs. That is what a source typo checker is for, and it
costs no coverage: prek run --all-files and the CI lint lane both run the
pre-commit stage.

One correction to the issue's diagnosis

#1489 proposed changing the yaml, check and consumer fragments. Only
yaml needs it. I checked the rendered consumer surface directly:

trunk -> {... 'pass_filenames': True, 'stages': ['pre-commit'], ...}

git-hooks.nix already defaults the hook to pre-commit, in all six consumer
variants that enable it — so flake-generated (direnv) consumers were never
affected, and an explicit pin there would be redundant. The test still asserts
that surface, so the guard does not depend on the default staying put.

Scaffolded consumers were affected (scaffold = true ships the identical
unfiltered definition) and are fixed by adopting this release.

Verification

Live repro on this branch's worktree, before the fix — the pre-commit round
passes and the message round fails:

$ git commit -F msg.txt        # msg.txt has a "# pick <sha> # …" comment line
typos (source typo checker).....................Passed
typos (source typo checker).....................Failed
- hook id: typos
- exit code: 2
  error: `afe` should be `safe`
    ╭▸ .git/worktrees/1489/COMMIT_EDITMSG:3:11

The identical commit after the fix: both rounds pass, exit 0.

Tests: TestTyposRunsOnlyAtPreCommit covers all three surfaces (runner render,
scaffold render, consumer surface). RED on both portable renders before the fix
(assert None == ['pre-commit']); the consumer case passed already, and I
confirmed that is not vacuous. The existing drift gate covers the two committed
YAMLs. Full suite 1302 passed, 20 skipped; prek run --all-files green.

Note on the diff

The explanatory comments deliberately do not spell out the offending
trigrams or a real example SHA — writing them out makes typos fail on this
very PR's source files. typos 1.46.3 does not honour inline
spellchecker:disable-line directives (verified), and widening .typos.toml
would weaken the linter repo-wide, so the comments describe the mechanism
instead of exhibiting it.

Follow-up filed

#1491 — the other two unfiltered local hooks (sync-manifest,
check-agent-identity) run 3x per commit for no benefit. Not bundled here:
neither receives a filename, so neither is broken, and check-agent-identity
needs a deliberate decision (its consumer fragment is pinned to pre-commit
while its yaml fragment is unpinned — the two surfaces disagree).

Refs: #1489

c-vigo added 2 commits August 13, 2026 11:18
A hook with no stages runs at every stage, and typos passes filenames, so
the commit-msg round hands it COMMIT_EDITMSG. Assert the pre-commit stage
on the runner render, the scaffold render and the flake-generated consumer
surface.

RED on both portable renders (stages is absent); the consumer surface
already passes, because git-hooks.nix defaults it to pre-commit.

Refs: #1489
The hook carried no stages, so it ran at every hook stage — and since it
passes filenames, the commit-msg round handed it COMMIT_EDITMSG. typos
reads short letter runs inside abbreviated git SHAs as misspelled words,
and git rebase --continue writes the rebase todo into that buffer as
comment lines, so a legitimate rebase was refused over a comment that never
enters the commit message. The workarounds it invites are editing git's own
todo or --no-verify, which this repo forbids.

Pin the stage in the yaml fragment of nix/hooks.nix, which renders both
committed configs. The check and consumer fragments need nothing:
git-hooks.nix already defaults the hook to pre-commit, so flake-generated
direnv consumers were never affected — the test covers that surface anyway,
so a future default change cannot reintroduce the trap silently.

Scaffolded consumers WERE affected and are fixed by adopting this release.
No coverage is lost: prek run --all-files and the CI lane run pre-commit.

Refs: #1489
@c-vigo
c-vigo merged commit e9a407d into dev Aug 13, 2026
14 checks passed
@c-vigo
c-vigo deleted the bugfix/1489-typos-pre-commit-stage branch August 13, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant