aboutsummaryrefslogtreecommitdiff
path: root/aux/assert-clang-format.sh
blob: c7ee6d7d5a818242afc60b65bb979b6b29fa29fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/sh
set -eu

if [ "${1:-}" = '--fix-in-place' ]; then
  find . -type f \( -name '*.h' -o -name '*.c' \) -exec clang-format -i {} \;
  exit 0
fi

# shellcheck disable=2016
find . -type f \( -name '*.h' -o -name '*.c' \) -print0 | xargs -0 -I{} sh -c '
	clang-format "$1" | diff - "$1" || {
		echo "Unformatted C code. To fix it, run:"
		echo "  ./aux/assert-clang-format.sh --fix-in-place"
		exit 1
	}
' _ {} \;