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:
2026-05-18 22:24:59 -04:00
parent 235adce596
commit 9759a4c3a3
10 changed files with 278 additions and 148 deletions
Executable
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
echo "Formatting with fourmolu..."
./hs fourmolu --mode inplace app/ src/ test/
echo "Linting with hlint..."
./hs hlint app/ src/ test/
echo "Building..."
./hs stack build --copy-bins --local-bin-path /work/build
+34
View File
@@ -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
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# Pre-push hook: check formatting and hlint before pushing.
# Installed by: scripts/install-hooks
set -euo pipefail
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
echo "--- Checking formatting with fourmolu..."
if ! "$PROJECT_DIR/hs" fourmolu --mode check app/ src/ test/; then
echo ""
echo "ERROR: Formatting check failed. Run './scripts/build' to auto-format."
echo " (fourmolu --mode inplace app/ src/ test/)"
exit 1
fi
echo "OK"
echo "--- Linting with hlint..."
if ! "$PROJECT_DIR/hs" hlint app/ src/ test/; then
echo ""
echo "ERROR: Hlint found warnings. Fix them before pushing."
exit 1
fi
echo "OK"
+24
View File
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Install git hooks for the roux-server project.
# Run once: ./scripts/install-hooks
set -euo pipefail
HOOK_SRC="$(cd "$(dirname "${BASH_SOURCE[0]}")/git-hooks" && pwd)"
# Determine git hooks directory — supports both regular repos and worktrees
GIT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/.git"
if [ -f "$GIT_DIR" ]; then
# Worktree: .git is a file pointing to the real gitdir
GIT_DIR="$(cut -d' ' -f2 "$GIT_DIR")"
fi
HOOK_DST="${GIT_DIR}/hooks"
mkdir -p "$HOOK_DST"
echo "Installing git hooks from $HOOK_SRC -> $HOOK_DST"
for hook in "$HOOK_SRC"/*; do
name=$(basename "$hook")
ln -sf "$hook" "$HOOK_DST/$name"
echo " $name installed"
done
echo "Done."
Executable
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
./hs stack exec roux-server -- "$@"
Executable
+12
View File
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
echo "Checking formatting with fourmolu..."
./hs fourmolu --mode check app/ src/ test/
echo "Linting with hlint..."
./hs hlint app/ src/ test/
echo "Running tests..."
./hs stack test