Skip to content

Comments

feat: add --stats flag to show file counts per step#446

Merged
jdx merged 4 commits intomainfrom
feat/add-stats-flag
Nov 20, 2025
Merged

feat: add --stats flag to show file counts per step#446
jdx merged 4 commits intomainfrom
feat/add-stats-flag

Conversation

@jdx
Copy link
Owner

@jdx jdx commented Nov 20, 2025

Summary

  • Adds new --stats flag to hk check and hk fix commands
  • Displays statistics about how many files match each step's patterns
  • Helps users understand which files will be processed by each step

Motivation

Users often want to understand the scope of what hk check or hk fix will process without actually running the linters/formatters. This is especially useful for:

  • Understanding which steps will process a given set of files
  • Debugging glob patterns and step configurations
  • Getting an overview of the repository structure

Changes

  • Added --stats flag to HookOptions (src/hook_options.rs:32)
  • Implemented Hook::stats() method to collect and display statistics (src/hook.rs:364)
  • Made Step::filter_files(), is_binary_file(), and is_symlink_file() public (src/step.rs)

Usage Examples

Show stats for modified files:

hk check --stats

Show stats for all repository files:

hk check --stats --all

Show stats with fix run type:

hk fix --stats --all

Show stats for specific step(s):

hk check --stats --step cargo-fmt --step prettier

Sample Output

Statistics for hook: check

Total files: 417
Run type: check

Files matching each step:

  actionlint           6  (1.4%)
  cargo-fmt            71  (17.0%)
  cargo-clippy         71  (17.0%)
  cargo-check          71  (17.0%)
  dbg                  71  (17.0%)
  eslint               1  (0.2%)
  newlines             407  (97.6%)
  trailing-whitespace  407  (97.6%)
  prettier             10  (2.4%)
  taplo                1  (0.2%)
  docs                 73  (17.5%)

Test plan

  • Built successfully with mise run build
  • Tested with hk check --stats (modified files)
  • Tested with hk check --stats --all (all files)
  • Tested with hk fix --stats --all (fix mode)
  • Tested with hk check --stats --step cargo-fmt --step prettier (specific steps)
  • All pre-commit and pre-push hooks pass

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]


Note

Adds a --stats flag to check/fix/run commands that prints per-step file match counts, with docs and usage updated.

  • CLI/Docs:
    • Add --stats flag to hk check, hk fix, and hk run (including commit-msg, pre-commit, pre-push, prepare-commit-msg).
    • Update docs (docs/cli/*.md) and usage specs (docs/cli/commands.json, hk.usage.kdl).
  • Core:
    • Implement Hook::stats() to compute and print per-step matched file counts, considering run type and skip reasons.
    • Wire flag in HookOptions to invoke stats mode.
  • Step API:
    • Make Step::filter_files, is_binary_file, and is_symlink_file public for reuse.

Written by Cursor Bugbot for commit 649f87e. This will update automatically on new commits. Configure here.

jdx and others added 3 commits November 20, 2025 07:26
Add a new --stats flag to the check and fix commands that displays
statistics about how many files match each step's patterns.

Changes:
- Added --stats flag to HookOptions (hook_options.rs:32)
- Implemented Hook::stats() method to collect and display statistics (hook.rs:364)
- Made Step::filter_files(), is_binary_file(), and is_symlink_file() public (step.rs:33,61,359)

The stats display shows:
- Total number of files being processed
- Run type (check or fix)
- File count and percentage for each step

Usage examples:
- hk check --stats              # Show stats for modified files
- hk check --stats --all        # Show stats for all repository files
- hk fix --stats --all          # Show stats with fix run type
- hk check --stats --step foo   # Show stats for specific step(s)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Move --stats flag to appear after --stash to maintain alphabetical
ordering of long-only flags as required by clap-sort test.

Fixes the test_subcommands_are_sorted test failure.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Generate documentation for the new --stats flag using mise run render.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Fix two bugs in the stats method:

1. Stats now checks if steps have commands for the current run type
   - Steps without check/fix commands are shown as skipped
   - Prevents misleading file counts for steps that won't actually run

2. Stats now respects skip configuration
   - Honors --skip-step CLI flags
   - Honors HK_SKIP_STEPS environment variable
   - Honors skip_steps from config
   - Shows appropriate skip reason for each skipped step

Skipped steps are now displayed with dimmed text showing the skip
reason instead of a file count, giving users an accurate picture of
what will actually run.

Examples:
- cargo-clippy  (skipped: profile not enabled (slow))
- cargo-fmt     (skipped: disabled via --skip-step cargo-fmt)
- dbg           (skipped: disabled via HK_SKIP_STEPS)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@jdx jdx merged commit a5997c1 into main Nov 20, 2025
14 checks passed
@jdx jdx deleted the feat/add-stats-flag branch November 20, 2025 14:06
@jdx jdx mentioned this pull request Nov 20, 2025
jdx added a commit that referenced this pull request Nov 21, 2025
## [1.23.0](https://github.com/jdx/hk/compare/v1.22.0..v1.23.0) -
2025-11-21

### 🚀 Features

- **(vacuum)** new builtin by [@scop](https://github.com/scop) in
[#414](#414)
- add --stats flag to show file counts per step by
[@jdx](https://github.com/jdx) in
[#446](#446)
- Plumb `stage` through CLI and PKL by
[@thejcannon](https://github.com/thejcannon) in
[#442](#442)

### 🐛 Bug Fixes

- **(cli)** check help description by [@scop](https://github.com/scop)
in [#439](#439)

### 📚 Documentation

- **(stash)** rephrase uncommitted -> unstaged by
[@scop](https://github.com/scop) in
[#451](#451)
- re-Remove "auto" stash value by
[@thejcannon](https://github.com/thejcannon) in
[#444](#444)
- Delete `schema.md` by [@thejcannon](https://github.com/thejcannon) in
[#445](#445)
- fix --fix description by [@scop](https://github.com/scop) in
[#450](#450)

### 📦️ Dependency Updates

- update actions/checkout digest to 93cb6ef by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#452](#452)
- update anthropics/claude-code-action digest to 6902c22 by
[@renovate[bot]](https://github.com/renovate[bot]) in
[#453](#453)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Release 1.23.0: expose `stage` setting via CLI/PKL, add
`--stage`/`--no-stage` and `--stats` flags, update docs/examples to
v1.23.0, and bump deps.
> 
> - **Release/Versioning**
> - Bump version to `1.23.0` across `Cargo.toml`, CLI specs, docs,
examples, and templates.
>   - Add `CHANGELOG.md` entry for 1.23.0.
> - **CLI & Config**
> - Expose `stage` setting: add `--stage` / `--no-stage` flags across
`commands.json`, `hk.usage.kdl`, and CLI docs.
>   - Add `--stats` flag to display per-step file counts.
>   - Include `stage` in `hk config get` available keys.
> - **Docs/Examples**
> - Update all `amends`/`import` URLs and version strings to `v1.23.0`.
>   - Clarify `--fix` help text; refresh CLI help pages.
> - **Code**
> - Update init template (`src/cli/init.rs`) and Pkl error message
example (`src/config.rs`) to `v1.23.0`.
> - **Dependencies**
> - Bump crates in `Cargo.lock` (e.g., `indexmap` → `2.12.1`,
`hashbrown` → `0.16.1`, `cc` → `1.2.47`, `zerocopy` → `0.8.28`, `insta`
→ `1.44.1`).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
91c5bd9. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: mise-en-dev <[email protected]>
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Nov 27, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [hk](https://github.com/jdx/hk) | minor | `1.22.0` -> `1.25.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>jdx/hk (hk)</summary>

### [`v1.25.0`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1250---2025-11-25)

[Compare Source](jdx/hk@v1.24.1...v1.25.0)

##### 🚀 Features

- add fix\_smart\_quotes builtin by [@&#8203;joonas](https://github.com/joonas) in [#&#8203;463](jdx/hk#463)

##### 🐛 Bug Fixes

- Use `stage = "<JOB_FILES>"` for the builtins by [@&#8203;thejcannon](https://github.com/thejcannon) in [#&#8203;465](jdx/hk#465)
- Actually makes `files` for step tests default to write keys by [@&#8203;thejcannon](https://github.com/thejcannon) in [#&#8203;464](jdx/hk#464)
- remove test cleanup to prevent race conditions by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;468](jdx/hk#468)

### [`v1.24.1`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1241---2025-11-22)

[Compare Source](jdx/hk@v1.24.0...v1.24.1)

##### ⚡ Performance

- show progress bars before expensive git status call by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;459](jdx/hk#459)

### [`v1.24.0`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1240---2025-11-21)

[Compare Source](jdx/hk@v1.23.0...v1.24.0)

##### 🚀 Features

- hook stage by [@&#8203;thejcannon](https://github.com/thejcannon) in [#&#8203;448](jdx/hk#448)

##### 🐛 Bug Fixes

- Pass/render `stdin` for `hk test` tests by [@&#8203;thejcannon](https://github.com/thejcannon) in [#&#8203;455](jdx/hk#455)

##### 📚 Documentation

- Fix `from_ref` docstring by [@&#8203;thejcannon](https://github.com/thejcannon) in [#&#8203;454](jdx/hk#454)

##### ⚡ Performance

- skip stash operations when no unstaged changes by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;457](jdx/hk#457)
- skip staging when jobs are skipped by conditions by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;458](jdx/hk#458)

### [`v1.23.0`](https://github.com/jdx/hk/blob/HEAD/CHANGELOG.md#1230---2025-11-21)

[Compare Source](jdx/hk@v1.22.0...v1.23.0)

##### 🚀 Features

- **(vacuum)** new builtin by [@&#8203;scop](https://github.com/scop) in [#&#8203;414](jdx/hk#414)
- add --stats flag to show file counts per step by [@&#8203;jdx](https://github.com/jdx) in [#&#8203;446](jdx/hk#446)
- Plumb `stage` through CLI and PKL by [@&#8203;thejcannon](https://github.com/thejcannon) in [#&#8203;442](jdx/hk#442)

##### 🐛 Bug Fixes

- **(cli)** check help description by [@&#8203;scop](https://github.com/scop) in [#&#8203;439](jdx/hk#439)

##### 📚 Documentation

- **(stash)** rephrase uncommitted -> unstaged by [@&#8203;scop](https://github.com/scop) in [#&#8203;451](jdx/hk#451)
- re-Remove "auto" stash value by [@&#8203;thejcannon](https://github.com/thejcannon) in [#&#8203;444](jdx/hk#444)
- Delete `schema.md` by [@&#8203;thejcannon](https://github.com/thejcannon) in [#&#8203;445](jdx/hk#445)
- fix --fix description by [@&#8203;scop](https://github.com/scop) in [#&#8203;450](jdx/hk#450)

##### 📦️ Dependency Updates

- update actions/checkout digest to [`93cb6ef`](jdx/hk@93cb6ef) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;452](jdx/hk#452)
- update anthropics/claude-code-action digest to [`6902c22`](jdx/hk@6902c22) by [@&#8203;renovate\[bot\]](https://github.com/renovate\[bot]) in [#&#8203;453](jdx/hk#453)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi4xOS4wIiwidXBkYXRlZEluVmVyIjoiNDIuMTkuNyIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
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