Add optional pre-commit hook for code formatting #5178
2 issues
code-review: Found 2 issues (1 high, 1 medium)
High
Pre-commit hook auto-formats unstaged files and may modify user's working tree - `.githooks/pre-commit:6-7`
The hook runs dotnet format (without --verify-no-changes), which mutates files in the working tree rather than just verifying. Combined with set -e, if formatting itself fails the hook aborts; but more critically, it formats the entire solution including unstaged changes the developer did not intend to commit. This causes side effects outside the commit's scope and can corrupt in-progress work, contradicting the PR description which states the hook should run dotnet format --verify-no-changes (check-only mode).
Also found at:
.githooks/pre-commit:6-9
Medium
`set -e` causes the hook to exit silently when `dotnet format` returns non-zero - `.githooks/pre-commit:2-7`
With set -e at the top of the script, any non-zero exit from dotnet format (e.g., when --verify-no-changes is added, or when the tool encounters an error) will terminate the script immediately, bypassing the helpful error message block below. The user will see only the initial "🔍 Checking code formatting..." line and a failed commit with no explanation of how to fix it.
Duration: 47.1s · Tokens: 49.5k in / 1.6k out · Cost: $0.26 (+extraction: $0.01, +merge: $0.00)
Annotations
Check failure on line 7 in .githooks/pre-commit
sentry-warden / warden: code-review
Pre-commit hook auto-formats unstaged files and may modify user's working tree
The hook runs `dotnet format` (without `--verify-no-changes`), which mutates files in the working tree rather than just verifying. Combined with `set -e`, if formatting itself fails the hook aborts; but more critically, it formats the entire solution including unstaged changes the developer did not intend to commit. This causes side effects outside the commit's scope and can corrupt in-progress work, contradicting the PR description which states the hook should run `dotnet format --verify-no-changes` (check-only mode).
Check failure on line 9 in .githooks/pre-commit
sentry-warden / warden: code-review
[PHR-3M5] Pre-commit hook auto-formats unstaged files and may modify user's working tree (additional location)
The hook runs `dotnet format` (without `--verify-no-changes`), which mutates files in the working tree rather than just verifying. Combined with `set -e`, if formatting itself fails the hook aborts; but more critically, it formats the entire solution including unstaged changes the developer did not intend to commit. This causes side effects outside the commit's scope and can corrupt in-progress work, contradicting the PR description which states the hook should run `dotnet format --verify-no-changes` (check-only mode).
Check warning on line 7 in .githooks/pre-commit
sentry-warden / warden: code-review
`set -e` causes the hook to exit silently when `dotnet format` returns non-zero
With `set -e` at the top of the script, any non-zero exit from `dotnet format` (e.g., when `--verify-no-changes` is added, or when the tool encounters an error) will terminate the script immediately, bypassing the helpful error message block below. The user will see only the initial "🔍 Checking code formatting..." line and a failed commit with no explanation of how to fix it.