This template sets up a cross-platform Git pre-commit
hook using Lefthook to validate the following things:
- Validate that committed files do not contain UTF-8 BOMs — except for extensions where BOMs are expected.
- Allows
.csproj
,.resx
,.ps1
, image and binary files to bypass - Flags
.csv
,.js
,.ts
,.svg
, etc. if they contain a BOM
- Allows
- Validate that committed files have lines not longer than 120 characters (or whatever is configured inside the
.editorconfig
file) — except for files where longer lines can be expected (e.g. Markdown files).- Allows text files and some others (like
.csv
) files to bypass - Flags other files if they contain lines exceeding 120 characters (or whatever is configured inside the
.editorconfig
file)
- Allows text files and some others (like
- Checks staged files on commit
- Checks the Operating System
- Runs scripts tailored for each system by using a runner script (
.ps1
for PowerShell,.sh
for Linux/MacOS)
- Follow the instructions from this page.
lefthook install
lefthook install
2. Try committing a file with a BOM, or with lines longer than 120 characters — the hook will block it.
lefthook run pre-commit
- ✅ Windows (via PowerShell/CMD)
- ✅ macOS / Linux (via Bash)