Improve README configuration documentation and husky hooks. - #2
Merged
Conversation
…nly lint staged files
**Problem:**
The pre-commit hook was causing unintended behavior by auto-fixing and staging
ALL modified files in the repository, not just the files the developer intended
to commit. This happened because:
1. The hook ran `npm run lint` which executed `eslint --fix` and
`prettier --write` on the entire codebase
2. After auto-fixing, it ran `git add -u` to re-stage all modified files
3. This meant a commit of one file (e.g., README) would inadvertently include
auto-fixed changes from completely unrelated files
This violated the principle of atomic commits and made it impossible to commit
a subset of changes while keeping other work-in-progress changes unstaged.
Additionally, the README's configuration section was minimal, listing only
environment variable names without explaining what each does or when to use
them.
**Solution:**
1. Installed `lint-staged` package to lint only staged files
2. Updated pre-commit hook to use `lint-staged` instead of global linting
3. Removed `git add -u` command that was re-staging all modified files
4. Updated `pre-commit` npm script to remove linting (now handled by lint-staged)
5. Enhanced README configuration section with detailed explanations
**Implementation Details:**
Pre-commit Hook Changes:
- `lint-staged` now runs first, applying ESLint and Prettier only to staged
`.ts` and `.tsx` files
- Auto-fixed files are automatically re-staged by `lint-staged`
- Full test suite, typecheck, and build still run on entire codebase for safety
- This ensures code quality while preserving developer intent about what to commit
Configuration in package.json:
```json
"lint-staged": {
"*.{ts,tsx}": [
"eslint --fix",
"prettier --write"
]
}
```
README Improvements:
- Added "Configuration Options" subsection with detailed descriptions
- Each option now includes: name, purpose, default value, and usage guidance
- Updated default model from llama-3.1-70b-versatile to openai/gpt-oss-120b
- Clarified relationship between env vars and constructor overrides
- Removed redundant bullet list from "Config" section
**Edge Cases:**
- Unstaged files remain untouched even if they have linting issues
- Developers can now commit partial changes while keeping WIP changes unstaged
- If linting fails on staged files, the commit is blocked (as intended)
- Integration with Husky remains intact
**Why This Matters:**
Atomic commits are essential for:
- Clear git history and easier code review
- Ability to cherry-pick or revert specific changes
- Separating refactoring from feature work
- Following git best practices
Better documentation reduces onboarding friction and helps users tune the
library for their specific use case.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem:
The pre-commit hook was causing unintended behavior by auto-fixing and staging ALL modified files in the repository, not just the files the developer intended to commit. This happened because:
npm run lintwhich executedeslint --fixandprettier --writeon the entire codebasegit add -uto re-stage all modified filesThis violated the principle of atomic commits and made it impossible to commit a subset of changes while keeping other work-in-progress changes unstaged.
Additionally, the README's configuration section was minimal, listing only environment variable names without explaining what each does or when to use them.
Solution:
lint-stagedpackage to lint only staged fileslint-stagedinstead of global lintinggit add -ucommand that was re-staging all modified filespre-commitnpm script to remove linting (now handled by lint-staged)Implementation Details:
Pre-commit Hook Changes:
lint-stagednow runs first, applying ESLint and Prettier only to staged.tsand.tsxfileslint-stagedConfiguration in package.json:
README Improvements:
Edge Cases:
Why This Matters:
Atomic commits are essential for:
Better documentation reduces onboarding friction and helps users tune the library for their specific use case.
🤖 Generated with Claude Code