Skip to content

Commit d89ddd9

Browse files
committed
chore: migrate pre-commit hooks to lefthook
1 parent 8e456c7 commit d89ddd9

2 files changed

Lines changed: 21 additions & 24 deletions

File tree

Makefile

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,17 @@ documentation-ci: deps documentation
2828
lint:
2929
stylua .
3030

31-
# installs the repo pre-commit hook that runs `make precommit` before every commit.
32-
precommit-install:
33-
@mkdir -p .git/hooks
34-
@printf '#!/usr/bin/env bash\nmake precommit\n' > .git/hooks/pre-commit
35-
@chmod +x .git/hooks/pre-commit
36-
@echo "pre-commit hook installed at .git/hooks/pre-commit"
37-
38-
# runs the pre-commit checks: lints all Lua files (auto-fixing anything that
39-
# isn't formatted), regenerates docs, and re-stages any files that changed.
31+
# installs the lefthook-managed git hooks defined in `lefthook.yml`.
32+
hooks-install:
33+
@command -v lefthook >/dev/null 2>&1 || { \
34+
echo "hooks-install: lefthook is not installed (brew install lefthook)" >&2; \
35+
exit 1; \
36+
}
37+
@lefthook install
38+
39+
# runs the lefthook pre-commit jobs on demand, outside of git.
4040
precommit:
41-
@set -eu; \
42-
if command -v stylua >/dev/null 2>&1; then \
43-
stylua .; \
44-
reformatted=$$(git diff --name-only -- '*.lua'); \
45-
if [ -n "$$reformatted" ]; then \
46-
echo "precommit: re-staging stylua-formatted files:"; \
47-
echo "$$reformatted" | sed 's/^/ /'; \
48-
git add $$reformatted; \
49-
fi; \
50-
stylua --check .; \
51-
else \
52-
echo "precommit: stylua not installed; skipping lint" >&2; \
53-
fi; \
54-
$(MAKE) documentation; \
55-
git add doc
41+
@lefthook run pre-commit
5642

5743
clean:
5844
rm -rf deps

lefthook.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pre-commit:
2+
parallel: false
3+
jobs:
4+
- name: stylua
5+
glob: "*.lua"
6+
run: stylua {staged_files}
7+
stage_fixed: true
8+
- name: documentation
9+
glob: "*.lua"
10+
run: make documentation
11+
stage_fixed: true

0 commit comments

Comments
 (0)