Config file name
Lefthook supports the following file names for the main config:
| Format | Acceptable config names |
|---|---|
| YAML | lefthook.yml lefthook.yaml .lefthook.yml .lefthook.yaml .config/lefthook.yml .config/lefthook.yaml |
| TOML | lefthook.toml .lefthook.toml .config/lefthook.toml |
| JSON | lefthook.json .lefthook.json .config/lefthook.json |
| JSONC | lefthook.jsonc .lefthook.jsonc .config/lefthook.jsonc |
If there are more than 1 file in the project, only one will be used, and you’ll never know which one. So, please, use one format in a project.
Filenames without the leading dot will also be looked up from the .config subdirectory.
Lefthook also merges an extra config with the name lefthook-local. All supported formats can be applied to this -local config. If you name your main config with the leading dot, like .lefthook.json, the -local config also must be named with the leading dot: .lefthook-local.json.
The -local config can be used without a main config file. This is useful when you want to use lefthook locally without imposing it on your teammates – just create a lefthook-local.yml file and add it to your global .gitignore.
Editor support
The JSON schema for the config is published at https://lefthook.dev/schema.json. Point your editor to it to get autocompletion, hover docs, and validation.
YAML (with yaml-language-server, e.g. the VS Code YAML extension):
# yaml-language-server: $schema=https://lefthook.dev/schema.json
pre-commit:
jobs:
- run: yarn lint
JSON:
{
"$schema": "https://lefthook.dev/schema.json",
"pre-commit": {
"jobs": [{ "run": "yarn lint" }]
}
}
TOML (with Taplo):
#:schema https://lefthook.dev/schema.json
[[pre-commit.jobs]]
run = "yarn lint"