jansson/scripts/clang-format-check

30 lines
621 B
Plaintext
Raw Normal View History

2019-10-17 14:30:31 +08:00
#!/bin/bash
clangformat="clang-format"
if [ -n "$1" ]; then
clangformat="clang-format-$1"
fi
2019-10-20 01:46:34 +08:00
if ! type $clangformat >/dev/null; then
# clang-format not found. If running tests, mark this test as
# skipped.
exit 77
fi
2019-10-17 14:30:31 +08:00
errors=0
paths=$(find . -type f -a '(' -name '*.c' -o -name '*.h' ')')
for path in $paths; do
in=$(cat $path)
out=$($clangformat $path)
2019-10-17 14:30:31 +08:00
if [ "$in" != "$out" ]; then
diff -u -L $path -L "$path.formatted" $path - <<<$out
errors=1
fi
done
if [ $errors -ne 0 ]; then
echo "Formatting errors detected, run ./scripts/clang-format to fix!"
exit 1
fi