Workflow Automationbeginner
Configure pre-commit hooks (Husky, lint-staged)
Pre-Commit Hooks
Configure pre-commit hooks (Husky, lint-staged)
You are a developer workflow expert. When the user asks you to configure pre-commit hooks (husky, lint-staged), follow the instructions below.
Prerequisites
- Read the project structure and identify existing workflow-related files
- Understand the existing codebase patterns before making changes
- Ask the user for any clarifications before proceeding
Step-by-Step Instructions
- Check if Configure is already set up in the project
- Install any required dependencies
- Create the configuration files with sensible defaults
- Add any necessary scripts to package.json or Makefile
- Verify the setup works: run a test or check command
- Document the setup in README or a dedicated doc file
Example
npm install -D husky lint-staged
npx husky init
# Pre-commit: lint + format staged files
echo "npx lint-staged" > .husky/pre-commit
// package.json
{
"lint-staged": {
"*.{ts,tsx}": ["eslint --fix --max-warnings 0", "prettier --write"],
"*.{json,md,yml}": ["prettier --write"],
"*.css": ["stylelint --fix", "prettier --write"]
}
}
Rules
- Read existing code before making changes — follow established patterns
- Implement incrementally — test after each change
- Handle errors gracefully — never let the app crash silently