diff --git a/.lefthook.yml b/.lefthook.yml index 2bae0a18fb..44f446accb 100644 --- a/.lefthook.yml +++ b/.lefthook.yml @@ -6,19 +6,28 @@ 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 + stage_fixed: true 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 + 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/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 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..503fcb7e88 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 "✅ Auto-fix complete (fixed files staged automatically)"