Files
oam/knowledge base/lefthook.md
2024-02-15 20:51:52 +01:00

2.7 KiB

Lefthook

  1. TL;DR
  2. Configuration
  3. Further readings
  4. Sources

TL;DR

# Installation.
go install 'github.com/evilmartians/lefthook@latest'
npm install 'lefthook' --save-dev
gem install 'lefthook'
brew install 'lefthook'

# Get help about any command.
lefthook help
lefthook help 'dump'

# Generate autocompletion scripts for the specified shells.
lefthook completion 'zsh'
lefthook completion -v 'fish' > "$HOME/.config/fish/completions/lefthook.fish"
source <(lefthook completion 'bash')

# Add configured hooks to the current git repository.
# Creates a basic configuration file in the repository if missing.
lefthook install

# Print the merged configuration from all files.
lefthook dump

# Add hook directories to the current repository.
lefthook add 'pre-commit'
lefthook add -dv 'commit-msg'

# Execute groups of hooks.
lefthook run 'pre-push'
lefthook run -v 'lint' --all-files
lefthook run 'pre-commit' -n --commands 'lint' --files 'lefthook.yml'

# Remove configured hooks from the current git repository.
lefthook uninstall
lefthook uninstall -cv

Configuration

Configuration files can be written in JSON, TOML or YAML.
Only one of them will be used, even if there are more than one in the repository. The chosen one will be the first one found during initialization, hence it is suggested to use a single configuration file in any of the above formats.

The main configuration file must exist and go by the name lefthook.<formatExtension> or .lefthook.<formatExtension>.

An extra configuration file named lefthook-local is merged with the main file if found upon initialization. All supported formats can be applied to this -local file.
If the main configuration file starts with the leading dot, the -local file must also start with the leading dot.

$ ls -A1 *lefthook*
.lefthook-local.json
.lefthook.yml

Configuration file example

Configuration files can extend other files recursively.

Further readings

Sources

All the references in the further readings section, plus the following: