- husky
- lint-staged
- @commitlint/cli
- @commitlint/config-conventional
- A
.huskydirectory - A
preparescript - A
lint-stagedconfig
Why wit Hooks Replace Husky
| Feature | Husky | wit |
|---|---|---|
| Installation | npm install husky | Built-in |
| Setup | npx husky install | wit hooks setup |
| Config file | .husky/ directory | .wit/hooks.json |
| Lint-staged | Separate package | Built-in staged config |
| Auto-install | Requires prepare script | wit hooks sync in postinstall |
Quick Start
Configuration File
wit uses.wit/hooks.json for hook configuration:
Config Locations
wit looks for config in these locations (in order):.wit/hooks.json(recommended)wit.config.jsonpackage.jsonunder"wit"key
Available Hooks
| Hook | Triggered | Can Abort |
|---|---|---|
pre-commit | Before commit is created | Yes |
post-commit | After commit is created | No |
commit-msg | After commit message entered | Yes |
pre-push | Before push to remote | Yes |
post-merge | After merge completes | No |
pre-rebase | Before rebase starts | Yes |
post-checkout | After branch switch | No |
prepare-commit-msg | Before message editor opens | No |
Commands
Setup Hooks
Add Hook Commands
Sync Configuration
List Hooks
Other Commands
Lint-Staged Style Configuration
Thestaged config runs commands only on staged files matching patterns:
Pattern Syntax
- Uses JavaScript regex patterns
- Files are passed as arguments to commands
- Use
{}placeholder to control file position:
Automatic Setup with npm
Add to yourpackage.json:
npm install.
Hook Definition Formats
Simple String
Array of Commands
Full Definition Object
Writing Custom Hooks
Basic Structure
Hooks are shell scripts in.wit/hooks/:
Pre-commit Hook
Block commits that don’t meet criteria:Commit Message Validation
Pre-push Hook
Run tests before pushing:Bypassing Hooks
Use--no-verify to skip hooks:
Hook Environment
Hooks have access to these environment variables:| Variable | Description |
|---|---|
$WIT_DIR | .wit directory path |
$WIT_WORK_DIR | Repository root |
$WIT_HOOK_TYPE | Current hook type |
$WIT_COMMIT | Commit hash (post-commit) |
$WIT_BRANCH | Current branch name |
Migration from Husky
Before (Husky + lint-staged)
After (wit only)
- husky
- lint-staged
- @commitlint/cli (use wit’s built-in validation)
Best Practices
Troubleshooting
Hook not running
Hook not running
- Check if hooks are synced:
wit hooks - Run sync:
wit hooks sync - Check permissions:
ls -la .wit/hooks/
Config changes not applied
Config changes not applied
Run
wit hooks sync after editing .wit/hooks.jsonBypassing hooks temporarily
Bypassing hooks temporarily
Use the
--no-verify flag:Hooks work locally but not for team
Hooks work locally but not for team
Ensure:
.wit/hooks.jsonis committedpostinstallscript callswit hooks sync- Team members run
npm installafter pulling