Skip to content

Commit 42d8f98

Browse files
justin808claude
andcommitted
Add ESLint to pre-commit hooks to prevent CI failures
Previously, pre-commit hooks only ran RuboCop, Prettier, and trailing newline checks, but did NOT run ESLint. This meant ESLint errors could slip through and only be caught in CI. Changes: - Created bin/lefthook/eslint-lint hook script that auto-fixes ESLint issues - Added ESLint hook to .lefthook.yml pre-commit configuration - Updated CLAUDE.md to document: - The complete list of pre-commit hooks that run - The monorepo structure with separate Pro package linting - Why CI lints both directories separately The hook follows the same pattern as other hooks: - Detects changed JS/TS files (staged + unstaged + untracked) - Runs ESLint with --fix to auto-correct issues - Re-stages fixed files automatically This prevents the frustrating situation where local commits succeed but CI fails on ESLint violations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 7210588 commit 42d8f98

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

.lefthook.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ pre-commit:
1111
rubocop:
1212
run: bin/lefthook/ruby-lint all-changed
1313

14+
eslint:
15+
run: bin/lefthook/eslint-lint all-changed
16+
1417
prettier:
1518
run: bin/lefthook/prettier-format all-changed
1619

CLAUDE.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ These requirements are non-negotiable. CI will fail if not followed.
1717

1818
Git hooks will automatically run linting on **all changed files (staged + unstaged + untracked)** before each commit - making it fast while preventing CI failures!
1919

20+
Pre-commit hooks automatically run:
21+
- **RuboCop** (auto-fix Ruby code style)
22+
- **ESLint** (auto-fix JS/TS code style)
23+
- **Prettier** (auto-format all supported files)
24+
- **Trailing newline checks** (ensure all files end with newlines)
25+
2026
**Note:** Git hooks are for React on Rails gem developers only, not for users who install the gem.
2127

2228
## Development Commands
@@ -90,13 +96,17 @@ Git hooks will automatically run linting on **all changed files (staged + unstag
9096

9197
## Project Architecture
9298

93-
### Dual Package Structure
99+
### Monorepo Structure
94100

95-
This project maintains both a Ruby gem and an NPM package:
101+
This is a monorepo containing both the open-source package and the Pro package:
96102

103+
- **Open Source**: Root directory contains the main React on Rails gem and package
104+
- **Pro Package**: `react_on_rails_pro/` contains the Pro features (separate linting/formatting config)
97105
- **Ruby gem**: Located in `lib/`, provides Rails integration and server-side rendering
98106
- **NPM package**: Located in `packages/react-on-rails/src/`, provides client-side React integration
99107

108+
**IMPORTANT**: The `react_on_rails_pro/` directory has its own Prettier/ESLint configuration. When CI runs, it lints both directories separately. The pre-commit hooks will catch issues in both directories.
109+
100110
### Core Components
101111

102112
#### Ruby Side (`lib/react_on_rails/`)

bin/lefthook/eslint-lint

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
# Lint and auto-fix JS/TS files with ESLint
3+
set -euo pipefail
4+
5+
CONTEXT="${1:-staged}"
6+
files="$(bin/lefthook/get-changed-files "$CONTEXT" '\.(js|jsx|ts|tsx)$')"
7+
8+
if [ -z "$files" ]; then
9+
echo "✅ No JS/TS files to lint with ESLint"
10+
exit 0
11+
fi
12+
13+
if [ "$CONTEXT" = "all-changed" ]; then
14+
echo "🔍 ESLint on all changed files:"
15+
else
16+
echo "🔍 ESLint on $CONTEXT files:"
17+
fi
18+
printf " %s\n" $files
19+
20+
# Run ESLint with auto-fix
21+
yarn run eslint $files --report-unused-disable-directives --fix
22+
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"
27+
fi

0 commit comments

Comments
 (0)