summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2024-08-07 17:51:00 +0300
committerBonfaceKilz2024-08-07 18:24:47 +0300
commit634206ea29d93c0a07afd01466a3042b1d33d6a8 (patch)
tree55d2d3fdc4a0338649c9b1538086900185d3f47c
parent96dc8bf8d85f0a1ea89addbca289c6188bf1dd8b (diff)
downloadgn-gemtext-634206ea29d93c0a07afd01466a3042b1d33d6a8.tar.gz
Create blog entry on creating scheme linter pre-commit hook.
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
-rw-r--r--topics/engineering/setting-up-a-basic-pre-commit-hook-for-linting-scheme-files.gmi31
1 files changed, 31 insertions, 0 deletions
diff --git a/topics/engineering/setting-up-a-basic-pre-commit-hook-for-linting-scheme-files.gmi b/topics/engineering/setting-up-a-basic-pre-commit-hook-for-linting-scheme-files.gmi
new file mode 100644
index 0000000..e8dd010
--- /dev/null
+++ b/topics/engineering/setting-up-a-basic-pre-commit-hook-for-linting-scheme-files.gmi
@@ -0,0 +1,31 @@
+# Setting Up a Basic Pre-Commit Hook for Linting Scheme Files
+
+* author: bonfacem
+* reviewed-by: jnduli
+
+Git executes hooks before/after events such as: commit, push and receive. A pre-commit hooks runs before a commit is finalized [0]. This post shows how to create a pre-commit hook for linting scheme files using `guix style`.
+
+```
+# Step 1: Create the hook
+touch .git/hooks/pre-commit
+
+# Step 2: Make the hook executable
+chmod +x .git/hooks/pre-commit
+
+# Step 3: Copy the following contents to the .git/hooks/pre-commit:
+
+#!/bin/sh
+
+# Run guix style on staged .scm files
+for file in $(git diff --cached --name-only --diff-filter=ACM | grep ".scm$"); do
+ if ! guix style --whole-file "$file"; then
+ echo "Linting failed for $file. Please fix the errors and try again."
+ exit 1
+ fi
+ git add $file
+done
+```
+
+## References:
+
+=> https://www.slingacademy.com/article/git-pre-commit-hook-a-practical-guide-with-examples/ [0] Git Pre-Commit Hook: A Practical Guide (with Examples)