chore: add a pre-commit hook to auto format erlang code

This commit is contained in:
Zaiming (Stone) Shi 2022-04-26 23:57:40 +02:00
parent 09b6648567
commit af69899619
4 changed files with 16 additions and 0 deletions

1
.gitattributes vendored
View File

@ -7,3 +7,4 @@ scripts/* text eol=lf
*.jpg -text
*.png -text
*.pdf -text
scripts/erlfmt -text

BIN
scripts/erlfmt Executable file

Binary file not shown.

11
scripts/git-hook-pre-commit.sh Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail
files="$(git diff --cached --name-only | grep -E '.*\.erl' || true)"
if [[ "${files}" == '' ]]; then
exit 0
fi
files="$(echo -e "$files" | xargs)"
# shellcheck disable=SC2086
./scripts/erlfmt -c $files

View File

@ -11,3 +11,7 @@ mkdir -p ".git/hooks"
if [ ! -L '.git/hooks/pre-push' ]; then
ln -sf '../../scripts/git-hook-pre-push.sh' '.git/hooks/pre-push'
fi
if [ ! -L '.git/hooks/pre-commit' ]; then
ln -sf '../../scripts/git-hook-pre-commit.sh' '.git/hooks/pre-commit'
fi