Add fourmolu + hlint with scripts and git hooks (Atlas-style)
- Create scripts/build, scripts/test, scripts/run, scripts/install-hooks - Create git-hooks/pre-commit (auto-format staged .hs files) - Create git-hooks/pre-push (check formatting + hlint before push) - Handle git worktrees correctly in hook installation - Run fourmolu on all source files to fix existing formatting
This commit is contained in:
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env bash
|
||||
# Pre-commit hook: format staged Haskell files with fourmolu.
|
||||
# Installed by: scripts/install-hooks
|
||||
set -euo pipefail
|
||||
|
||||
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||
|
||||
# Get staged .hs files (handles filenames with spaces)
|
||||
staged=$(git -C "$PROJECT_DIR" diff --cached --name-only --diff-filter=ACM -- '*.hs')
|
||||
if [ -z "$staged" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Collect the files into an array
|
||||
mapfile -t files <<< "$staged"
|
||||
|
||||
echo "--- Formatting staged Haskell files with fourmolu..."
|
||||
if ! "$PROJECT_DIR/hs" fourmolu --mode inplace "${files[@]}"; then
|
||||
echo "ERROR: fourmolu formatting failed" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Re-stage any files that were modified by formatting
|
||||
changed=0
|
||||
for f in "${files[@]}"; do
|
||||
if ! git -C "$PROJECT_DIR" diff --quiet "$f"; then
|
||||
git -C "$PROJECT_DIR" add "$f"
|
||||
changed=$((changed + 1))
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$changed" -gt 0 ]; then
|
||||
echo "--- Formatted $changed file(s) — re-staged automatically"
|
||||
fi
|
||||
Reference in New Issue
Block a user