This project uses pre-commit hooks to ensure code quality and prevent common issues before they reach the repository. Never use --no-verify to bypass these checks.
- Runs on all
.tsand.tsxfiles - Uses
tsc -b --noEmitfor full project type checking - Catches type errors before they reach CI/CD
- Runs on Supabase Edge Functions (
supabase/functions/**/*.ts) - Only runs if Deno is installed
- Validates edge function types
- Runs on all JavaScript/TypeScript files
- Automatically fixes issues with
--fix - Fails if there are unfixable errors or warnings
- Formats all code files
- Ensures consistent code style
- Runs on JS, TS, JSON, YAML, CSS files
- Runs when
index.htmlorpublic/_headerschanges - Validates Content Security Policy hashes
- Ensures inline scripts match CSP headers
Using --no-verify bypasses all pre-commit checks, which can lead to:
❌ Type errors in production
- Breaks the build in CI/CD
- Causes runtime errors
- Wastes time debugging issues that could have been caught
❌ Code style inconsistencies
- Makes code reviews harder
- Creates merge conflicts
- Violates team conventions
❌ Security vulnerabilities
- CSP violations can expose XSS vulnerabilities
- Bypassed linting can miss security issues
❌ Broken builds
- Fails CI/CD pipeline
- Blocks other developers
- Delays deployments
Pre-commit hooks are installed automatically when you run:
npm installThis installs Husky hooks in .husky/ directory.
If hooks aren't installed, run:
npm run hooks:installSolution:
# Run type check to see errors
npx tsc -b --noEmit
# Fix the errors in your code
# Then commit again
git commit -m "fix: resolve type errors"Solution:
# Run ESLint to see errors
npm run lint
# Auto-fix what's possible
npm run lint:fix
# Manually fix remaining issues
# Then commit againSolution:
# Format all files
npm run format
# Then commit again
git commit -m "style: format code"Solution:
# Verify CSP hash
npm run verify:csp
# If it fails, update the hash
npm run update:csp
# Then commit againOptimization tips:
- Stage only the files you're working on
- TypeScript checking runs on entire project (necessary for type safety)
- Consider committing smaller, focused changes
- Use
git add -pfor partial staging
# Only if absolutely necessary
git commit --no-verify -m "emergency: critical hotfix"
# Then immediately create a follow-up commit to fix issues
git commit -m "fix: address type errors from emergency commit"Better approach:
- Fix the issues locally
- Commit without
--no-verify - Push to a hotfix branch
- Create PR for review
# 1. Make your changes
vim src/components/MyComponent.tsx
# 2. Run checks manually (optional but recommended)
npm run lint
npm run format
npx tsc -b --noEmit
# 3. Stage your changes
git add src/components/MyComponent.tsx
# 4. Commit (hooks run automatically)
git commit -m "feat: add new component"
# 5. If hooks fail, fix issues and try again
npm run lint:fix
git add .
git commit -m "feat: add new component"# Stage all changes
git add .
# Or stage specific patterns
git add src/**/*.tsx
# Commit (hooks run on all staged files)
git commit -m "refactor: update components".husky/pre-commit- Main pre-commit hook script.husky/_/- Husky runtime files
.lintstagedrc.json- Defines what runs on which files
tsconfig.json- Main TypeScript configtsconfig.app.json- App-specific configtsconfig.node.json- Node-specific config
- Package.json
eslintConfigsection - Runs React, TypeScript, and custom rules
.prettierrc.json- Code formatting rules.prettierignore- Files to skip
Pre-commit hooks mirror what runs in CI/CD:
| Check | Pre-Commit | CI/CD |
|---|---|---|
| TypeScript | ✅ | ✅ |
| ESLint | ✅ | ✅ |
| Prettier | ✅ | ✅ |
| Unit Tests | ❌ | ✅ |
| E2E Tests | ❌ | ✅ |
| Build | ❌ | ✅ |
This means:
- Pre-commit catches most issues early
- CI/CD runs additional checks (tests, build)
- Both must pass for code to be merged
# Check if Husky is installed
ls -la .husky/
# Reinstall hooks
rm -rf .husky
npm run hooks:install
# Verify git hooks path
git config core.hooksPath
# Should output: .huskyTypeScript checks the entire project because:
- Type changes can affect other files
- Ensures no breaking changes
- Catches cross-file type errors
To speed up:
- Keep project dependencies updated
- Use incremental compilation (already configured)
- Commit smaller changes more frequently
# Run lint with fix
npx eslint --fix src/
# Stage the fixes
git add .
# Try commit again
git commit -m "fix: resolve linting issues"- Run
npm run lintbefore committing large changes - Fix type errors as you code
- Use editor integration for ESLint and Prettier
- Commit small, focused changes
- Read error messages carefully
- Ask for help if stuck
- Use
--no-verifyunless absolutely necessary - Ignore type errors
- Commit without testing locally
- Stage unrelated changes together
- Skip reading pre-commit output
- Force push without checking hooks passed
Install these extensions:
- ESLint (dbaeumer.vscode-eslint)
- Prettier (esbenp.prettier-vscode)
- TypeScript and JavaScript Language Features (built-in)
Configuration (.vscode/settings.json):
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"typescript.tsdk": "node_modules/typescript/lib"
}- WebStorm/IntelliJ: Built-in support for ESLint, Prettier, and TypeScript
- Vim/Neovim: Use ALE or CoC with ESLint and Prettier plugins
- Sublime Text: Use LSP-typescript and SublimeLinter-eslint
If you encounter issues with pre-commit hooks:
- Check this documentation
- Run manual checks to identify the issue
- Fix the reported errors
- Ask team members for help
- Create an issue if it's a hook configuration problem
Remember: Pre-commit hooks are your friend! They catch issues early and save time in the long run. 🚀