lefthook
v1.10.0
Node.js、Ruby、Python、その他多くの種類のプロジェクトのGit Hooks Manager。
ドキュメント
はじめに投稿を読んでください
Go (> = 1.23):
go install github.com/evilmartians/lefthook@latestNPMで:
npm install lefthook --save-devRubyの場合:
gem install lefthookPythonの場合:
pip install lefthookLefthook:Apt、Brew、Wingetなどをインストールする方法を備えたインストールガイド。
フックを構成し、それらを一度インストールして忘れてください。その下の魔法に頼ってください。
# Configure your hooks
vim lefthook.yml
# Install them to the git project
lefthook install
# Enjoy your work with git
git add -A && git commit -m ' ... ' lefthook.yml構成オプションの構成。より多くの速度を与えます。ドキュメント
pre-push :
parallel : true独自のリストが必要な場合。カスタムおよび事前に構築された例。
pre-commit :
commands :
frontend-linter :
run : yarn eslint {staged_files}
backend-linter :
run : bundle exec rubocop --force-exclusion {all_files}
frontend-style :
files : git diff --name-only HEAD @{push}
run : yarn stylelint {files}ファイルのリストをフィルタリングする場合。ここでは、より多くのグローブパターンの例を見つけることができます。
pre-commit :
commands :
backend-linter :
glob : " *.rb " # glob filter
exclude : ' (^|/)(application|routes).rb$ ' # regexp filter
run : bundle exec rubocop --force-exclusion {all_files}相対パスでコマンドを実行したい場合
pre-commit :
commands :
backend-linter :
root : " api/ " # Careful to have only trailing slash
glob : " *.rb " # glob filter
run : bundle exec rubocop {all_files}Onelineコマンドで十分でない場合は、ファイルを実行できます。ドキュメント
commit-msg :
scripts :
" template_checker " :
runner : bashコマンドのグループを制御したい場合。ドキュメント
pre-push :
commands :
packages-audit :
tags :
- frontend
- linters
run : yarn lint
gems-audit :
tags :
- backend
- security
run : bundle auditDocker環境にいる場合。ドキュメント
pre-commit :
scripts :
" good_job.js " :
runner : docker run -it --rm <container_id_or_name> {cmd}フロントエンド/バックエンド開発者であり、不必要なコマンドをスキップしたり、何かをDockerにオーバーライドしたい場合。ドキュメント
# lefthook-local.yml
pre-push :
exclude_tags :
- frontend
commands :
packages-audit :
skip : trueフックグループを直接実行したい場合。
$ lefthook run pre-commit特定のコマンドのグループを直接実行する場合。
fixer :
commands :
ruby-fixer :
run : bundle exec rubocop --force-exclusion --safe-auto-correct {staged_files}
js-fixer :
run : yarn eslint --fix {staged_files} $ lefthook run fixerRefthookプリントを出力オプションで制御できます。
output :
- execution
- failure例を確認してください