Skip to content

feat(builtins): add keep_sorted, cspell and cspell_commit_message builtins - #1898

Merged
jdx merged 4 commits into
mainfrom
claude/github-discussion-1897-e73a38
Nov 23, 2026
Merged

jdx merged 4 commits into
mainfrom
claude/github-discussion-1897-e73a38

Conversation

@jdx

@jdx jdx commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Adds three builtins requested in #1897, so projects using keep-sorted or cspell no longer have to write these steps by hand:

  • keep_sorted checks that lines between keep-sorted start and keep-sorted end comments are sorted, and sorts them in fix mode. It runs on every text file, since keep-sorted only touches marked blocks. It also has a check_diff, so hk fix can apply its changes as a patch.
  • cspell spell-checks text files. It respects the project's cspell config (words, ignorePaths, and so on). Files are passed with --file, so names with glob characters like notes[1].md are checked as literal paths. A batch where every file is in ignorePaths passes. cspell has no fixer, so this step is check-only.
  • cspell_commit_message spell-checks the commit message in a commit-msg hook. It ignores git's # comment lines, which would otherwise flag branch and file names. With git commit --verbose, it also skips everything below the scissors line. Errors are reported as COMMIT_EDITMSG:line:col with the message's own line numbers, and an ignorePaths entry like .git doesn't skip the message.
amends "package://github.com/jdx/hk/releases/download/v2.6.0/hk@2.6.0#/Config.pkl"
import "package://github.com/jdx/hk/releases/download/v2.6.0/hk@2.6.0#/Builtins.pkl"

hooks {
  ["pre-commit"] {
    fix = true
    steps {
      ["keep-sorted"] = Builtins.keep_sorted
      ["cspell"] = Builtins.cspell
    }
  }
  ["commit-msg"] {
    steps {
      ["cspell"] = Builtins.cspell_commit_message
    }
  }
}

The tools come from mise as aqua:google/keep-sorted (not in the mise registry) and cspell (npm:cspell).

Validation: 12 new hk test cases cover check, fix and diff for keep-sorted, and good and bad files, config words, ignorePaths, glob-character filenames and invalid config for cspell. Tool stubs pin keep-sorted 0.11.0 and cspell 10.5.2. test/cspell_commit_message.bats covers a misspelled message, and a message whose comments and verbose diff contain unknown words. All of these pass locally. In test/builtins_tests.bats, go, ruby, asciidoctor and ktlint builtins failed locally because of toolchain problems on the dev machine, not this change; CI runs them in a clean environment.

The discussion also suggests porting more of treefmt-nix's formatters. That's not part of this PR.

AI-assisted — Tool: Claude Code; model: anthropic/claude-opus-5-5; version: unavailable.

🤖 Generated with Claude Code


Note

Low Risk
New optional builtins and tests only; no changes to core hook execution, auth, or existing step behavior.

Overview
Adds three Special Purpose builtins so users can drop in Builtins.keep_sorted, Builtins.cspell, and Builtins.cspell_commit_message instead of hand-writing hook steps.

keep_sorted runs on text files with lint / fix and a check_diff path via hk util format-diff. cspell lints text with project config support (words, ignorePaths), uses --file for literal paths, and includes embedded hk test cases.

cspell_commit_message is commit-msg–only: a shell/awk pipeline strips git comment lines (respecting core.commentChar / core.commentString and auto), drops content below the verbose scissors line, then pipes the message to cspell lint as stdin://COMMIT_EDITMSG.

Test coverage adds mise tool stubs for cspell 10.5.2 and keep-sorted 0.11.0, plus test/cspell_commit_message.bats for misspellings, comment/diff stripping, and comment-marker edge cases.

Reviewed by Cursor Bugbot for commit 490aa12. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Tests
    • Added checks for commit-message spelling validation, including misspellings, Git comment lines, verbose diffs, custom and automatic comment characters, and unreadable message files.
    • Added test tool version definitions for cspell and keep-sorted to support consistent test environments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AI-Assisted: Tool: Claude Code; model: unavailable; version: 2.1.330
Entire-Checkpoint: 01M844CV8956JW46Y6KRFN2NN7
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 24 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a619d76 and 490aa12.

Files ignored due to path filters: 1

  • pkl/builtins/cspell_commit_message.pkl is excluded by !**/*.pkl
Files selected for processing: 1

  • test/cspell_commit_message.bats

No actionable comments were generated in the recent review.

Walkthrough

The changes add tool stubs for cspell and keep-sorted, and add Bats tests for the cspell commit-message hook.

Changes: Commit message spelling hook tests

Layer / File(s) Summary
Tool stubs
test/builtin_tool_stubs/cspell, test/builtin_tool_stubs/keep-sorted
The stubs specify cspell version 10.5.2 and keep-sorted version 0.11.0, including their sources.
Hook setup and assertions
test/cspell_commit_message.bats
The tests configure cspell for the commit-msg hook. They check misspelled messages, Git comment handling with the default, custom, and auto comment markers, verbose diff content, missing message-file handling, and marker selection when core.commentString and core.commentChar are configured.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Merge Risk: Minimal · previous review a619d · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the feature (adding keep_sorted, cspell and cspell_commit_message builtins), and the changeset does add these builtins. It is a conventional-commit style title that is short and specif…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the feature (adding keep_sorted, cspell and cspell_commit_message builtins), and the changeset does add these builtins. It is a conventional-commit style title that is short and specific. It does not cover the tool stubs or tests, which is expected.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7c16eea and a619d76.

Files ignored due to path filters: 1

  • pkl/builtins/cspell_commit_message.pkl is excluded by !**/*.pkl
Files selected for processing: 1

  • test/cspell_commit_message.bats

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The changes since the previous review appear safe to merge.

Summary

Adds keep_sorted, cspell, and cspell_commit_message builtins with pinned test tools and test cases.

  • keep_sorted checks and sorts marked blocks in text files.
  • cspell checks text files using project spelling settings.
  • cspell checks commit messages without checking Git comments or diffs.

Reviews (3) · Last reviewed commit: "fix(builtins): skip only git's chosen ma..." · Reviewed by Greptile

Comment thread pkl/builtins/cspell_commit_message.pkl Resolved
Comment thread pkl/builtins/cspell_commit_message.pkl Resolved
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AI-Assisted: Tool: Claude Code; model: unavailable; version: 2.1.330
Entire-Checkpoint: 01M844WV6ZG19Z2FXWQ8HS1ZQH

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7c16eea. Configure here.

Comment thread pkl/builtins/cspell_commit_message.pkl Resolved
…_message

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AI-Assisted: Tool: Claude Code; model: unavailable; version: 2.1.330
Entire-Checkpoint: 01M84526GYBX1K1JAYGPVQR1WE
Comment thread pkl/builtins/cspell_commit_message.pkl Resolved
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AI-Assisted: Tool: Claude Code; model: unavailable; version: 2.1.330
Entire-Checkpoint: 01M845AH05RD28DB32R0QPG6MP
@jdx
jdx merged commit 65ae3cb into main Nov 23, 2026
27 checks passed
@jdx
jdx deleted the claude/github-discussion-1897-e73a38 branch November 23, 2026 12:36
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