What is Lefthook?
Lefthook is a Git hooks manager. It is
- Fast
- Powerful
- Simple
How lefthook works?
You
- Configure
lefthook.yml - Run
lefthook install
Lefthook installs the configured hooks into .git/hooks/. Hook is a simple script that calls lefthook run {hook-name} when executed.
How to install lefthook?
The most common way is to use the package manager of your project, e.g. gem or npm package.
You can also install lefthook via Homebrew, winget, yum, apt, apk, scoop
Example configuration
Run linters on pre-commit hook.
# lefthook.yml
pre-commit:
parallel: true
jobs:
- run: yarn run stylelint --fix {staged_files}
glob: "*.css"
stage_fixed: true
- run: yarn run eslint --fix "{staged_files}"
glob:
- "*.ts"
- "*.js"
- "*.tsx"
- "*.jsx"
stage_fixed: true