@@ -8,30 +8,50 @@ exec 1>&2
88
99echo " Running Pre-Commit Hooks..."
1010
11- # Get staged nix files
11+ # Get staged files
1212STAGED_NIX_FILES=$( git diff --cached --name-only --diff-filter=ACM | grep ' \.nix$' || true)
13+ STAGED_MD_FILES=$( git diff --cached --name-only --diff-filter=ACM | grep ' \.md$' || true)
14+ LOCK_CHANGED=$( git diff --cached --name-only --diff-filter=ACM | grep ' flake\.lock$' || true)
1315
16+ # --- NIX CHECKS ---
1417if [ -n " $STAGED_NIX_FILES " ]; then
15- echo " Formatting..."
18+ echo " Processing Nix files..."
19+ echo " -> Formatting..."
1620 nix run nixpkgs#alejandra -- -q $STAGED_NIX_FILES
1721
18- echo " Checking for dead code..."
22+ echo " -> Checking for dead code..."
1923 nix run nixpkgs#deadnix -- -e $STAGED_NIX_FILES
2024
21- echo " Running statix..."
22- # Statix requires single files
25+ echo " -> Running statix..."
2326 for file in $STAGED_NIX_FILES ; do
24- echo " -> $file "
27+ echo " - $file "
2528 nix run nixpkgs#statix -- fix " $file "
2629 done
2730
2831 # Re-stage formatted files
2932 git add $STAGED_NIX_FILES
3033fi
3134
32- echo " Running nix flake check..."
33- nix flake check
35+ if [ -n " $STAGED_NIX_FILES " ] || [ -n " $LOCK_CHANGED " ]; then
36+ echo " Running nix flake check..."
37+ nix flake check
38+ fi
39+
40+ # --- MARKDOWN CHECKS ---
41+ if [ -n " $STAGED_MD_FILES " ]; then
42+ echo " Processing Markdown files..."
43+ echo " -> Formatting..."
44+ nix run nixpkgs#prettier -- --write $STAGED_MD_FILES --ignore-path .gitignore
45+
46+ echo " -> Linting..."
47+ # We run lint on the whole repo to be safe, but only if md files changed
48+ nix run nixpkgs#markdownlint-cli2 -- ' **/*.md' ' #.direnv' ' #result' ' #.git'
49+
50+ # Re-stage formatted files
51+ git add $STAGED_MD_FILES
52+ fi
3453
54+ # --- AI TRACE SCAN ---
3555echo " Scanning for AI traces..."
3656if command -v ai-trace-scan & > /dev/null; then
3757 ai-trace-scan --staged --quiet
0 commit comments