Add ruff auto-format PreToolUse hook for git commits #80
No reviewers
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ldraney/claude-custom!80
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "79-ruff-auto-format"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds a PreToolUse hook that automatically runs
ruff formaton staged Python files before anygit commitcommand. This eliminates ruff formatting failures in CI by ensuring all committed Python code is already formatted.Changes
hooks/auto-ruff-format.sh(new): PreToolUse hook that detectsgit commitcommands, finds staged.pyfiles, locates ruff (PATH,.venv/bin/ruff,venv/bin/ruff), formats them, and re-stages. Uses the same CWD resolution pattern asblock-main-commits.sh. Always exits 0 (never blocks commits).settings.json: Registers the hook in thePreToolUse->Bashmatcher list, positioned afterblock-main-commits.sh(branch checks run before formatting).Test Plan
git commitin a Python repo with staged.pyfiles.pyfiles are stagedcdReview Checklist
Related
PR #80 Review
BLOCKERS
Undocumented change to
hooks/check-issue.sh-- The PR body lists only two files changed (hooks/auto-ruff-format.shandsettings.json), but the diff includes a 7-line modification tohooks/check-issue.shthat adds repo-root resolution for.claude-no-enforceopt-out checks. This is a functional change to an unrelated hook (issue enforcement) that is not mentioned in the Summary or Changes sections. This is scope creep -- it should either be (a) removed from this PR and filed as its own issue, or (b) documented in the PR body under Changes with a clear rationale for why it belongs here.Cosmetic key reordering in
settings.json-- The bottom of the diff swaps the order ofskipDangerousModePermissionPromptandeffortLevel. This is a no-op semantically (JSON key order does not matter), but it is an unnecessary change that inflates the diff and makes merge conflict resolution harder. It should be reverted so only the hook registration line appears in the settings.json diff.NITS
Existing
check-ruff-before-commit.shoverlap -- The repo already containshooks/check-ruff-before-commit.shwhich fires ongit commitin Python repos and runsruff check(lint violations, blocking). The newauto-ruff-format.shrunsruff format(formatting, non-blocking). These are complementary but the PR body does not mention the relationship or explain why both are needed. A one-line note in the Summary or Related section would help future readers understand the distinction (lint check vs. format fix).grep -oEportability -- Line 17 ofauto-ruff-format.shusesgrep -oEwhich relies on GNU grep. The host is Arch Linux (grep aliased to rg per MEMORY.md). Previous hooks (PR #66) had portability fixes for exactly this pattern. This works today but is fragile. Consider whetherrgor a bash-native pattern match would be more robust.CD resolution does not handle
~or$HOME-- TheCD_TARGETextraction on line 31 handles absolute paths (/...) and relative paths, but if an agent emitscd ~/project, the~will not expand inside double quotes. This is the same limitation asblock-main-commits.shso it is inherited, not introduced -- just noting it.ruff formaterror output swallowed -- Line 66:"$RUFF" format "$FULL_PATH" 2>/dev/null || truesilently discards ruff stderr. If ruff crashes (e.g., config parse error), the user gets no feedback. Consider logging to stderr (2>&2or removing the redirect) since the hook never blocks anyway.SOP COMPLIANCE
79-ruff-auto-formatreferences issue #79check-issue.shmodification (see BLOCKER #1)Closes #79.env, credentials, or sensitive data in diffcheck-issue.shchange is unrelated scope creep (BLOCKER #1);settings.jsonkey reordering is cosmetic noise (BLOCKER #2)VERDICT: NOT APPROVED
Two blockers must be addressed before merge:
check-issue.shchange (or split to its own issue/PR) and update the PR body if it stays.settings.json.PR #80 Re-Review
BLOCKERS
None.
NITS
check-issue.sh: The diff shows 13 lines changed inhooks/check-issue.sh, but this change already exists onmain(the repo_root opt-out improvement). This is a merge-base artifact -- the branch was created before that commit landed on main. The merge will resolve cleanly with no actual content change. Not a blocker, but a rebase would eliminate the noise. Low priority since it merges clean.SOP COMPLIANCE
79-ruff-auto-formatreferences issue #79)Closes #79Hook Logic Review
git commitcommands (regex pattern matches compound commands)block-main-commits.shpattern (proven pattern).pyfiles viagit diff --cached --diff-filter=d(excludes deleted).venv/bin/ruff,venv/bin/ruff(covers standard layouts)|| true,2>/dev/null)block-main-commits.shin settings.json (branch check before format)VERDICT: APPROVED
Previous blockers resolved: the
check-issue.shchange is a merge-base artifact (already on main), and the cosmeticsettings.jsonkey reordering was reverted. The diff now contains only the intended deliverable plus a harmless merge-base ghost. Hook logic is solid.