~starkingdoms/starkingdoms

ref: 7a460d3cb9e24fdecd3c4ca8f79758071b1c6afc starkingdoms/.git-hooks/pre-commit -rwxr-xr-x 1.2 KiB
7a460d3c — core remove old builder dockerfile, move new ones into folder 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash

echo "Checking your formatting..."

HAS_ISSUES=0
FIRST_FILE=1

for file in $(git diff --name-only --staged); do
    FMT_RESULT="$(rustfmt --edition 2021 --skip-children --force --write-mode diff $file 2>/dev/null || true)"
    if [ "$FMT_RESULT" != "" ]; then
        if [ $FIRST_FILE -eq 0 ]; then
            echo -n ", "
        fi
        echo -n "$file (rustfmt)"
        HAS_ISSUES=1
        FIRST_FILE=0
    fi
done

cd starkingdoms-client

for file in $(git diff --name-only --staged); do
  if [ $file == starkingdoms-client* ]; then
    FMT_RESULT="$(yarn prettier $file --check 2>&1 > /dev/null || true)"
    if [ "$FMT_RESULT" != "" ]; then
      if [ $FIRST_FILE -eq 0 ]; then
        echo -n ", "
      fi
      echo -n "$file (prettier)"
      HAS_ISSUES=1
      FIRST_FILE=0
    fi
  fi
done

if [ $HAS_ISSUES -eq 0 ]; then
    echo "Everything looks good! Proceeding with commit."
    exit 0
fi

echo ""
echo ". Your code has formatting issues in files listed above. Format each file before proceeding with commit."
echo ". For Rust files, execute 'rustfmt path/to/file.rs' in 'server/'."
echo ". For client files, execute 'yarn prettier path/to/file --write' in 'starkingdoms-client/'."
exit 1