Skip to content

Commit c5880a9

Browse files
justin808claude
andcommitted
Make trailing-newlines hook auto-fix instead of validate
- Add stage_fixed: true to trailing-newlines command in .lefthook.yml - Update check-trailing-newlines script to automatically add missing newlines instead of just reporting them - Improve ruby-autofix success message to clarify that files are auto-staged - Ensures consistency with other auto-fixing hooks (autofix, eslint, prettier) This completes the pre-commit hook race condition fix by making all auto-fixing commands use Lefthook's stage_fixed feature uniformly. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 1680276 commit c5880a9

File tree

3 files changed

+4
-13
lines changed

3 files changed

+4
-13
lines changed

.lefthook.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pre-commit:
2727

2828
trailing-newlines:
2929
run: bin/lefthook/check-trailing-newlines all-changed
30+
stage_fixed: true
3031

3132
pre-push:
3233
commands:

bin/lefthook/check-trailing-newlines

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,13 @@ else
1616
echo "🔍 Checking trailing newlines on $CONTEXT files..."
1717
fi
1818

19-
failed_files=""
2019
for file in $files; do
2120
if [ -f "$file" ] && [ -s "$file" ]; then
2221
if ! tail -c 1 "$file" | grep -q '^$'; then
23-
echo "❌ Missing trailing newline: $file"
24-
failed_files="$failed_files $file"
22+
echo "🔧 Adding trailing newline to: $file"
23+
echo >> "$file"
2524
fi
2625
fi
2726
done
2827

29-
if [ -n "$failed_files" ]; then
30-
echo ""
31-
echo "❌ Trailing newline check failed!"
32-
echo "💡 Add trailing newlines to:$failed_files"
33-
echo "🔧 Quick fix: for file in$failed_files; do echo >> \"\$file\"; done"
34-
echo "🚫 Skip hook: git commit --no-verify"
35-
exit 1
36-
fi
37-
3828
echo "✅ All files have proper trailing newlines"

bin/lefthook/ruby-autofix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ printf " %s\n" $files
1919

2020
bundle exec rake autofix
2121

22-
echo "Completed auto-fixing all linting violations"
22+
echo "✅ Auto-fix complete (fixed files staged automatically)"

0 commit comments

Comments
 (0)