Skip to content

Commit efbb9d6

Browse files
committed
feat(hooks): migrate from pre-commit to hk
- Replace pre-commit with hk v1.44.1+ for git hooks - Add ~/hk.pkl with full step coverage: trailing-whitespace, newlines, check-merge-conflict, typos, gitleaks (staged-only), yamllint, editorconfig-checker, shellcheck, shfmt, zsh-syntax-check, stylua, luacheck, prettier, standardrb, check-json, check-executables-have-shebangs, check-added-large-files, no-yadm-alt-symlinks, mise-fmt, renovate-config-validator, commitlint - Set HK_STASH_UNTRACKED=false via hk.pkl env block to prevent scanning $HOME for untracked files (GIT_WORK_TREE=$HOME in yadm) — requires v1.44.1+ see jdx/hk#860 - Set stash=none to avoid recursive hook invocation from hk install --global - Move linting tools (shellcheck, shfmt, stylua, gitleaks, typos, prettier, editorconfig-checker) from linux.toml to global.toml for macOS+Linux parity - Update CI: replace pre-commit/action + Python setup with jdx/mise-action + hk check --all; consolidate luacheck job into hk - Add dotfiles:lint and dotfiles:fix mise tasks - Remove ~/.pre-commit-config.yaml - Update docs: pre-commit.md -> hk.md docs(hk): clarify yadm-specific hk settings - Document HK_STASH_UNTRACKED=false and stash=none rationale - Fix version requirement to v1.44.1 in hk.md - Remove stale check-yaml entry from step table - Renumber CI secret-scanning job (4 not 5) after luacheck consolidation - Clean up commented luacheck line in global.toml fix(hooks): address hk CI failures - shfmt: exclude *.zsh and vendor files (.iterm2_shell_integration); zsh-syntax-check already validates zsh syntax - typos: add _typos.toml to suppress -ot/-Ot shell test operators and exclude clickhouse-best-practices skill (deliberate typo examples) - prettier: auto-fix blank-line normalization in several .md files - luacheck: restore as separate CI job; removed from hk.pkl because hk's global exclude hides .config/nvim from scanning - Remove luacheck from linux.toml (handled by GH Actions job) - Remove prettier declaration inside global.toml duplicate comment
1 parent fe1568e commit efbb9d6

14 files changed

Lines changed: 334 additions & 261 deletions

File tree

.agents/docs/hk.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# hk
2+
3+
Git hooks and code quality checks for the yadm dotfiles repo.
4+
5+
## Configuration
6+
7+
**Main config**: `~/hk.pkl` (requires hk v1.44.1+ for yadm bare-repo support)
8+
9+
hk is installed globally via `hk install --global`, using Git 2.54+ config-based hooks. It runs as a
10+
silent no-op in repos without an `hk.pkl`.
11+
12+
### yadm-specific settings
13+
14+
Two settings in `hk.pkl` are needed to make hk work cleanly in the yadm context
15+
(`GIT_WORK_TREE=$HOME`):
16+
17+
- **`env { ["HK_STASH_UNTRACKED"] = "false" }`** — prevents hk from running
18+
`git status --untracked-files=all` which would scan the entire home directory (~45s).
19+
See [jdx/hk#860](https://github.com/jdx/hk/discussions/860).
20+
- **`stash = "none"`** on pre-commit and fix hooks — avoids a recursive hook invocation.
21+
`hk install --global` registers a hook on every git operation, so the internal `git stash push`
22+
hk runs during pre-commit would re-trigger hk and cause an infinite loop. Downside: if you have
23+
unstaged changes, auto-fixers may modify them alongside staged content.
24+
25+
## Running Hooks Manually
26+
27+
```bash
28+
# Run all checks (all files)
29+
yadm enter hk check --all
30+
31+
# Run all fixers (all files)
32+
yadm enter hk fix --all
33+
34+
# Via mise tasks
35+
mise run dotfiles:lint
36+
mise run dotfiles:fix
37+
38+
# Dry-run: see what would run and why
39+
yadm enter hk check --plan
40+
```
41+
42+
## Configured Steps
43+
44+
| Step | Purpose |
45+
| ------------------------------- | ---------------------------------------------- |
46+
| trailing-whitespace | Remove trailing whitespace |
47+
| newlines | Ensure files end with a newline |
48+
| check-merge-conflict | Detect leftover conflict markers |
49+
| typos | Spell checking for source code |
50+
| gitleaks | Secret detection |
51+
| yamllint | YAML linting |
52+
| editorconfig-checker | EditorConfig conformance |
53+
| shellcheck | Shell script linting (bash/sh only) |
54+
| shfmt | Shell script formatting |
55+
| zsh-syntax-check | Zsh syntax validation (`zsh -n`) |
56+
| stylua | Lua formatting (top-level .lua only) |
57+
| prettier | JSON/Markdown/YAML formatting |
58+
| standardrb | Ruby linting/formatting |
59+
| check-json | JSON parse validation |
60+
| check-executables-have-shebangs | Executables must have shebangs |
61+
| check-added-large-files | Block files over 500KB |
62+
| no-yadm-alt-symlinks | Reject staged yadm alt symlinks |
63+
| mise-fmt | Mise config formatting |
64+
| renovate-config-validator | Renovate config validation |
65+
| commitlint | Conventional commit messages (commit-msg hook) |
66+
67+
## CI Integration
68+
69+
The `hk-check` job in `.github/workflows/ci.yml` runs `hk check --all` via `jdx/mise-action`,
70+
which installs all tools from the Linux mise config. Steps skipped in CI:
71+
72+
- `standardrb` — requires Ruby gems not in CI
73+
- `renovate-config-validator` — requires npm:renovate
74+
- `no-yadm-alt-symlinks` — requires yadm
75+
76+
The separate `luacheck` job lints `.config/nvim/**/*.lua` since hk's global exclude
77+
hides `.config/` from scanning.
78+
79+
## Bypassing Hooks
80+
81+
```bash
82+
HK=0 yadm commit -m "wip" # skip all hk hooks
83+
HK_SKIP_STEPS=typos yadm commit -m "" # skip a specific step
84+
```
85+
86+
## Debugging
87+
88+
```bash
89+
yadm enter hk check -v # verbose output
90+
yadm enter hk check --plan # show what would run
91+
yadm enter hk check --step stylua # single step
92+
```
93+
94+
## Adding New Steps
95+
96+
Edit `~/hk.pkl`. Add to the `fast_steps` mapping — it is shared across `pre-commit`, `fix`, and
97+
`check` hooks. Run `yadm enter hk validate` to verify syntax.
98+
99+
## Version Management
100+
101+
hk version is managed by mise (`hk = "latest"` in `~/.config/mise/conf.d/global.toml`).
102+
When upgrading, bump the `amends` and `import` URLs in `~/hk.pkl` to match the new version.
103+
104+
Check current version: `hk --version`

.agents/docs/neovim.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,11 @@ Three plugins coordinate to provide seamless YADM support:
5757
### Components
5858

5959
1. **gitsigns-yadm.nvim** (`lua/plugins/gitsigns.lua`)
60-
6160
- Detects when a buffer is tracked by YADM (not a regular git repo)
6261
- Sets `vim.b.yadm_tracked = true` on YADM-tracked buffers via `on_yadm_attach`
6362
- Passes YADM context to gitsigns so hunks/blame work correctly
6463

6564
2. **snacks.nvim** (`lua/plugins/snacks.lua`)
66-
6765
- Helper functions detect YADM context:
6866
- `is_yadm_repo(dir)` - Returns true if in `~` or `~/.config`
6967
- `yadm_opts()` - Returns git args: `--git-dir ~/.local/share/yadm/repo.git --work-tree ~`

.agents/docs/pre-commit.md

Lines changed: 0 additions & 72 deletions
This file was deleted.

.agents/docs/tmux.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ The tmux configuration is managed through yadm. The main config is universal (wo
1111
Tmux automatically loads configuration from the XDG location `~/.config/tmux/tmux.conf`.
1212

1313
1. **`~/.config/tmux/tmux.conf`** (Universal config)
14-
1514
- Shared across all machines
1615
- Features:
1716
- Mouse support enabled
@@ -23,15 +22,13 @@ Tmux automatically loads configuration from the XDG location `~/.config/tmux/tmu
2322
- Sources `~/.config/tmux/tmux.platform.conf` if it exists (for platform-specific overrides)
2423

2524
2. **`~/.config/tmux/tmux.platform.conf##distro.qts`** (QNAP overrides)
26-
2725
- QNAP-specific terminal fixes, sourced by the main config
2826
- Features:
2927
- `xterm-keys on` for Ctrl-arrow compatibility
3028
- Home/End key fixes
3129
- `default-terminal "tmux-256color"` with italics and RGB overrides
3230

3331
3. **`~/.shellrc/zshrc.d/configs/tmux.zsh##distro.qts`** (Shell integration, QNAP only)
34-
3532
- Shell-side tmux configuration for auto-starting tmux on QNAP
3633
- Sets environment variables for tmux behavior:
3734
- `ZSH_TMUX_AUTOCONNECT=true`
@@ -60,11 +57,9 @@ The configuration uses TPM (Tmux Plugin Manager) with these plugins:
6057
### Related Files
6158

6259
- **`~/.config/nvim/lua/plugins/vim-tmux-navigator.lua`**
63-
6460
- Neovim integration for tmux navigation (universal, works on all machines)
6561

6662
- **`~/.config/yadm/bootstrap.d/910-install-tmux-plugin-manager.sh`**
67-
6863
- Bootstrap script to install TPM and plugins (universal)
6964

7065
- **`~/.config/yadm/bootstrap.d/915-install-tmux-terminfo.sh##os.Linux,distro.qts`**

.config/mise/conf.d/global.toml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,28 @@ dua = "latest"
1111

1212
# ── Developer workflow ────────────────────────────────────────────────
1313
# Git hook manager
14-
pre-commit = "latest"
14+
hk = "latest"
15+
# Pkl configuration language (required by hk)
16+
pkl = "latest"
1517
# Utilities for working with patches (filterdiff, etc.)
1618
"github:twaugh/patchutils" = "latest"
1719

20+
# ── Linting & formatting ──────────────────────────────────────────────
21+
# Secrets scanner for git repos
22+
"aqua:gitleaks/gitleaks" = "latest"
23+
# Shell script linter
24+
shellcheck = "latest"
25+
# Shell script formatter
26+
shfmt = "latest"
27+
# Lua code formatter
28+
stylua = "latest"
29+
# Spell checker for source code
30+
typos = "latest"
31+
# EditorConfig file format checker
32+
"aqua:editorconfig-checker/editorconfig-checker" = "latest"
33+
# JSON/Markdown/YAML formatter
34+
prettier = "latest"
35+
1836
# ── AI tooling ────────────────────────────────────────────────────────
1937
# Lazy-loading MCP server proxy for AI tools
2038
"npm:lazy-mcp" = "latest"

.config/mise/conf.d/linux.toml##os.Linux

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,8 @@ btop = "latest"
5353
"aqua:sharkdp/hyperfine" = "latest"
5454

5555
# ── Linting & formatting ──────────────────────────────────────────────
56-
# Secrets scanner for git repos
57-
"aqua:gitleaks/gitleaks" = "latest"
58-
# Shell script linter
59-
shellcheck = "latest"
60-
# Lua code formatter
61-
stylua = "latest"
56+
# (linting tools are declared in global.toml; luacheck runs in its own CI job
57+
# via nebularg/actions-luacheck action)
6258

6359
# ── npm ───────────────────────────────────────────────────────────────
6460
# Auto-generates table of contents in Markdown

.config/mise/conf.d/tasks.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ run = "~/.config/yadm/scripts/update.zsh"
2626
description = "Run dotfile health checks"
2727
run = "~/.config/yadm/scripts/run-checks.zsh"
2828

29+
[tasks."dotfiles:lint"]
30+
description = "Run all linters on dotfiles"
31+
run = "yadm enter hk check --all"
32+
33+
[tasks."dotfiles:fix"]
34+
description = "Run all fixers on dotfiles"
35+
run = "yadm enter hk fix --all"
36+
2937
# ── Git ───────────────────────────────────────────────────────────────
3038

3139
[tasks."git:push"]

.config/opencode/AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ the task needs them.
3838
- [Mise Tasks](~/.agents/docs/mise-tasks.md) - Task automation for dotfiles
3939
- [Neovim](~/.agents/docs/neovim.md) - Configuration structure and plugin management
4040
- [Mise](~/.agents/docs/mise.md) - Runtime versions and CLI tools
41-
- [Pre-commit](~/.agents/docs/pre-commit.md) - Hooks and code quality checks
41+
- [hk](~/.agents/docs/hk.md) - Git hooks and code quality checks
4242
- [Renovate Bot](~/.agents/docs/renovate.md) - Dependency update configuration and troubleshooting
4343
- [Writing Style](~/.agents/docs/writing-style.md) - Pedro's tone, formatting, and MR conventions
4444
- [GDK Dotfiles](~/.agents/docs/gdk-dotfiles.md) - Personal files synced into `$GDK_ROOT/gitlab`
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
# Runs a command silently; only shows output on failure
3+
output=$("$@" 2>&1)
4+
code=$?
5+
[ $code -ne 0 ] && printf '%s\n' "$output"
6+
exit $code

0 commit comments

Comments
 (0)