Skip to content

Commit f0a1b0f

Browse files
justin808claude
andcommitted
Fix pre-commit hooks to properly lint Pro directory
The previous hooks only linted files in the root directory, but the react_on_rails_pro/ directory has its own ESLint and Prettier configs that need to be run separately. This caused CI failures when Pro files had linting issues that weren't caught locally. Changes: 1. Updated bin/lefthook/eslint-lint to: - Separate files into root and Pro directories - Run ESLint in Pro directory with Pro's config for Pro files - Track exit codes and fail if either check fails 2. Updated bin/lefthook/prettier-format to: - Separate files into root and Pro directories - Run Prettier in Pro directory with Pro's config for Pro files 3. Fixed Prettier formatting in commonWebpackConfig.js: - Condensed multi-line conditional to single line per Pro's config This ensures local pre-commit hooks match CI behavior exactly, preventing the frustrating situation where commits succeed locally but fail in CI. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4260503 commit f0a1b0f

File tree

3 files changed

+87
-25
lines changed

3 files changed

+87
-25
lines changed

bin/lefthook/eslint-lint

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,55 @@ if [ -z "$files" ]; then
1010
exit 0
1111
fi
1212

13-
if [ "$CONTEXT" = "all-changed" ]; then
14-
echo "🔍 ESLint on all changed files:"
15-
else
16-
echo "🔍 ESLint on $CONTEXT files:"
13+
# Separate files into root and Pro directories
14+
root_files=$(echo "$files" | grep -v '^react_on_rails_pro/' || true)
15+
pro_files=$(echo "$files" | grep '^react_on_rails_pro/' || true)
16+
17+
exit_code=0
18+
19+
# Lint root files
20+
if [ -n "$root_files" ]; then
21+
if [ "$CONTEXT" = "all-changed" ]; then
22+
echo "🔍 ESLint on root changed files:"
23+
else
24+
echo "🔍 ESLint on root $CONTEXT files:"
25+
fi
26+
printf " %s\n" $root_files
27+
28+
if ! yarn run eslint $root_files --report-unused-disable-directives --fix; then
29+
exit_code=1
30+
fi
31+
32+
# Re-stage files if running on staged or all-changed context
33+
if [ "$CONTEXT" = "staged" ] || [ "$CONTEXT" = "all-changed" ]; then
34+
echo $root_files | xargs -r git add
35+
fi
1736
fi
18-
printf " %s\n" $files
1937

20-
# Run ESLint with auto-fix
21-
yarn run eslint $files --report-unused-disable-directives --fix
38+
# Lint Pro files (using Pro's ESLint config)
39+
if [ -n "$pro_files" ]; then
40+
if [ "$CONTEXT" = "all-changed" ]; then
41+
echo "🔍 ESLint on Pro changed files:"
42+
else
43+
echo "🔍 ESLint on Pro $CONTEXT files:"
44+
fi
45+
printf " %s\n" $pro_files
46+
47+
# Strip react_on_rails_pro/ prefix for running in Pro directory
48+
pro_files_relative=$(echo "$pro_files" | sed 's|^react_on_rails_pro/||')
2249

23-
# Re-stage files if running on staged or all-changed context
24-
if [ "$CONTEXT" = "staged" ] || [ "$CONTEXT" = "all-changed" ]; then
25-
echo $files | xargs -r git add
26-
echo "✅ Re-staged fixed files"
50+
if ! (cd react_on_rails_pro && yarn run eslint $pro_files_relative --report-unused-disable-directives --fix); then
51+
exit_code=1
52+
fi
53+
54+
# Re-stage files if running on staged or all-changed context
55+
if [ "$CONTEXT" = "staged" ] || [ "$CONTEXT" = "all-changed" ]; then
56+
echo $pro_files | xargs -r git add
57+
fi
58+
fi
59+
60+
if [ $exit_code -eq 0 ]; then
61+
echo "✅ ESLint checks passed"
2762
fi
63+
64+
exit $exit_code

bin/lefthook/prettier-format

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,45 @@ if [ -z "$files" ]; then
1010
exit 0
1111
fi
1212

13-
if [ "$CONTEXT" = "all-changed" ]; then
14-
echo "💅 Prettier on all changed files:"
15-
else
16-
echo "💅 Prettier on $CONTEXT files:"
13+
# Separate files into root and Pro directories
14+
root_files=$(echo "$files" | grep -v '^react_on_rails_pro/' || true)
15+
pro_files=$(echo "$files" | grep '^react_on_rails_pro/' || true)
16+
17+
# Format root files
18+
if [ -n "$root_files" ]; then
19+
if [ "$CONTEXT" = "all-changed" ]; then
20+
echo "💅 Prettier on root changed files:"
21+
else
22+
echo "💅 Prettier on root $CONTEXT files:"
23+
fi
24+
printf " %s\n" $root_files
25+
26+
yarn run prettier --write $root_files
27+
28+
# Re-stage files if running on staged or all-changed context
29+
if [ "$CONTEXT" = "staged" ] || [ "$CONTEXT" = "all-changed" ]; then
30+
echo $root_files | xargs -r git add
31+
fi
1732
fi
18-
printf " %s\n" $files
1933

20-
yarn run prettier --write $files
34+
# Format Pro files (using Pro's Prettier config)
35+
if [ -n "$pro_files" ]; then
36+
if [ "$CONTEXT" = "all-changed" ]; then
37+
echo "💅 Prettier on Pro changed files:"
38+
else
39+
echo "💅 Prettier on Pro $CONTEXT files:"
40+
fi
41+
printf " %s\n" $pro_files
2142

22-
# Re-stage files if running on staged or all-changed context
23-
if [ "$CONTEXT" = "staged" ] || [ "$CONTEXT" = "all-changed" ]; then
24-
echo $files | xargs -r git add
25-
echo "✅ Re-staged formatted files"
43+
# Strip react_on_rails_pro/ prefix for running in Pro directory
44+
pro_files_relative=$(echo "$pro_files" | sed 's|^react_on_rails_pro/||')
45+
46+
(cd react_on_rails_pro && yarn run prettier --write $pro_files_relative)
47+
48+
# Re-stage files if running on staged or all-changed context
49+
if [ "$CONTEXT" = "staged" ] || [ "$CONTEXT" = "all-changed" ]; then
50+
echo $pro_files | xargs -r git add
51+
fi
2652
fi
53+
54+
echo "✅ Prettier formatting complete"

react_on_rails_pro/spec/dummy/config/webpack/commonWebpackConfig.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ const commonWebpackConfig = () => {
5555
// Shakapacker 9 defaults to namedExport: true, but our code uses default imports
5656
// Override to use the old behavior for backward compatibility
5757
config.module.rules.forEach((rule) => {
58-
if (
59-
rule.test &&
60-
(rule.test.test('example.module.scss') || rule.test.test('example.module.css'))
61-
) {
58+
if (rule.test && (rule.test.test('example.module.scss') || rule.test.test('example.module.css'))) {
6259
if (Array.isArray(rule.use)) {
6360
rule.use.forEach((loader) => {
6461
if (

0 commit comments

Comments
 (0)