From 9a227bac0ea436e64e120739794ec11e6d3f7611 Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Wed, 12 Nov 2025 21:27:38 -1000 Subject: [PATCH 1/3] Fix release script pre-commit hook race condition - Use lefthook's stage_fixed option instead of manual git add - Prevents index.lock errors when hooks run in parallel - Fixes rake release task failures during version bumps --- .lefthook.yml | 7 +++++++ bin/lefthook/prettier-format | 10 ---------- bin/lefthook/ruby-autofix | 6 +----- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/.lefthook.yml b/.lefthook.yml index 2bae0a18fb..3262dfdf62 100644 --- a/.lefthook.yml +++ b/.lefthook.yml @@ -6,16 +6,23 @@ pre-commit: parallel: true commands: autofix: + glob: "*.{rb,rake,ru}" run: bin/lefthook/ruby-autofix all-changed + stage_fixed: true rubocop: + glob: "*.{rb,rake,ru}" run: bin/lefthook/ruby-lint all-changed eslint: + glob: "*.{js,jsx,ts,tsx}" run: bin/lefthook/eslint-lint all-changed + stage_fixed: true prettier: + glob: "*.{js,jsx,ts,tsx,json,md,yml,yaml}" run: bin/lefthook/prettier-format all-changed + stage_fixed: true trailing-newlines: run: bin/lefthook/check-trailing-newlines all-changed diff --git a/bin/lefthook/prettier-format b/bin/lefthook/prettier-format index 44a7cbf786..7caf687d4d 100755 --- a/bin/lefthook/prettier-format +++ b/bin/lefthook/prettier-format @@ -24,11 +24,6 @@ if [ -n "$root_files" ]; then printf " %s\n" $root_files yarn run prettier --write $root_files - - # Re-stage files if running on staged or all-changed context - if [ "$CONTEXT" = "staged" ] || [ "$CONTEXT" = "all-changed" ]; then - echo $root_files | xargs -r git add - fi fi # Format Pro files (using Pro's Prettier config) @@ -44,11 +39,6 @@ if [ -n "$pro_files" ]; then pro_files_relative=$(echo "$pro_files" | sed 's|^react_on_rails_pro/||') (cd react_on_rails_pro && yarn run prettier --write $pro_files_relative) - - # Re-stage files if running on staged or all-changed context - if [ "$CONTEXT" = "staged" ] || [ "$CONTEXT" = "all-changed" ]; then - echo $pro_files | xargs -r git add - fi fi echo "✅ Prettier formatting complete" diff --git a/bin/lefthook/ruby-autofix b/bin/lefthook/ruby-autofix index f3a257c798..7bb0c31644 100755 --- a/bin/lefthook/ruby-autofix +++ b/bin/lefthook/ruby-autofix @@ -19,8 +19,4 @@ printf " %s\n" $files bundle exec rake autofix -# Re-stage files if running on staged or all-changed context -if [ "$CONTEXT" = "staged" ] || [ "$CONTEXT" = "all-changed" ]; then - echo $files | xargs -r git add - echo "✅ Re-staged formatted files" -fi +echo "Completed auto-fixing all linting violations" From 1680276716e6138720899978c74de74b1432428d Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Wed, 12 Nov 2025 21:39:47 -1000 Subject: [PATCH 2/3] Fix lefthook glob patterns to match files in subdirectories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update all glob patterns from "*.{...}" to "**/*.{...}" for recursive matching - Ensures pre-commit hooks run on files in all subdirectories (lib/, spec/, etc.) - Remove redundant git add from eslint-lint script (lefthook handles via stage_fixed) - Add missing stage_fixed to rubocop command for consistency 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .lefthook.yml | 9 +++++---- bin/lefthook/eslint-lint | 10 ---------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/.lefthook.yml b/.lefthook.yml index 3262dfdf62..fa818140a2 100644 --- a/.lefthook.yml +++ b/.lefthook.yml @@ -6,21 +6,22 @@ pre-commit: parallel: true commands: autofix: - glob: "*.{rb,rake,ru}" + glob: "**/*.{rb,rake,ru}" run: bin/lefthook/ruby-autofix all-changed stage_fixed: true rubocop: - glob: "*.{rb,rake,ru}" + glob: "**/*.{rb,rake,ru}" run: bin/lefthook/ruby-lint all-changed + stage_fixed: true eslint: - glob: "*.{js,jsx,ts,tsx}" + glob: "**/*.{js,jsx,ts,tsx}" run: bin/lefthook/eslint-lint all-changed stage_fixed: true prettier: - glob: "*.{js,jsx,ts,tsx,json,md,yml,yaml}" + glob: "**/*.{js,jsx,ts,tsx,json,md,yml,yaml}" run: bin/lefthook/prettier-format all-changed stage_fixed: true diff --git a/bin/lefthook/eslint-lint b/bin/lefthook/eslint-lint index 700325e453..a864d89e1c 100755 --- a/bin/lefthook/eslint-lint +++ b/bin/lefthook/eslint-lint @@ -34,11 +34,6 @@ if [ -n "$root_and_packages_pro_files" ]; then if ! yarn run eslint $root_and_packages_pro_files --fix; then exit_code=1 fi - - # Re-stage files if running on staged or all-changed context - if [ "$CONTEXT" = "staged" ] || [ "$CONTEXT" = "all-changed" ]; then - echo $root_and_packages_pro_files | xargs -r git add - fi fi # Lint react_on_rails_pro files (using Pro gem's ESLint config) @@ -56,11 +51,6 @@ if [ -n "$react_on_rails_pro_files" ]; then if ! (cd react_on_rails_pro && yarn run eslint $react_on_rails_pro_files_relative --fix); then exit_code=1 fi - - # Re-stage files if running on staged or all-changed context - if [ "$CONTEXT" = "staged" ] || [ "$CONTEXT" = "all-changed" ]; then - echo $react_on_rails_pro_files | xargs -r git add - fi fi if [ $exit_code -eq 0 ]; then From c5880a97718bb3e28d16a167ca6e4432344ea62d Mon Sep 17 00:00:00 2001 From: Justin Gordon Date: Wed, 12 Nov 2025 21:43:26 -1000 Subject: [PATCH 3/3] Make trailing-newlines hook auto-fix instead of validate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- .lefthook.yml | 1 + bin/lefthook/check-trailing-newlines | 14 ++------------ bin/lefthook/ruby-autofix | 2 +- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/.lefthook.yml b/.lefthook.yml index fa818140a2..44f446accb 100644 --- a/.lefthook.yml +++ b/.lefthook.yml @@ -27,6 +27,7 @@ pre-commit: trailing-newlines: run: bin/lefthook/check-trailing-newlines all-changed + stage_fixed: true pre-push: commands: diff --git a/bin/lefthook/check-trailing-newlines b/bin/lefthook/check-trailing-newlines index 4cd6dd87ed..b7f2c91c7d 100755 --- a/bin/lefthook/check-trailing-newlines +++ b/bin/lefthook/check-trailing-newlines @@ -16,23 +16,13 @@ else echo "🔍 Checking trailing newlines on $CONTEXT files..." fi -failed_files="" for file in $files; do if [ -f "$file" ] && [ -s "$file" ]; then if ! tail -c 1 "$file" | grep -q '^$'; then - echo "❌ Missing trailing newline: $file" - failed_files="$failed_files $file" + echo "🔧 Adding trailing newline to: $file" + echo >> "$file" fi fi done -if [ -n "$failed_files" ]; then - echo "" - echo "❌ Trailing newline check failed!" - echo "💡 Add trailing newlines to:$failed_files" - echo "🔧 Quick fix: for file in$failed_files; do echo >> \"\$file\"; done" - echo "🚫 Skip hook: git commit --no-verify" - exit 1 -fi - echo "✅ All files have proper trailing newlines" diff --git a/bin/lefthook/ruby-autofix b/bin/lefthook/ruby-autofix index 7bb0c31644..503fcb7e88 100755 --- a/bin/lefthook/ruby-autofix +++ b/bin/lefthook/ruby-autofix @@ -19,4 +19,4 @@ printf " %s\n" $files bundle exec rake autofix -echo "Completed auto-fixing all linting violations" +echo "✅ Auto-fix complete (fixed files staged automatically)"