3 function setup_for_format() {
4 if [ -z "${CLANG_FORMAT}" ]; then
5 CLANG_FORMAT=clang-format
7 echo "LINT: Using binary $CLANG_FORMAT"
8 CLANG_FORMAT_WHITELIST="util/ci/clang-format-whitelist.txt"
10 files_to_lint="$(find src/ -name '*.cpp' -or -name '*.h')"
13 function check_format() {
14 echo "Checking format..."
20 for f in ${files_to_lint}; do
21 d=$(diff -u "$f" <(${CLANG_FORMAT} "$f") || true)
23 if ! [ -z "$d" ]; then
24 whitelisted=$(awk '$1 == "'$f'" { print 1 }' "$CLANG_FORMAT_WHITELIST")
26 # If file is not whitelisted, mark a failure
27 if [ -z "${whitelisted}" ]; then
28 errorcount=$((errorcount+1))
30 printf "The file %s is not compliant with the coding style" "$f"
31 if [ ${errorcount} -gt 50 ]; then
32 printf "\nToo many errors encountered previously, this diff is hidden.\n"
42 if [ "$fail" = 1 ]; then
43 echo "LINT reports failure."
52 function fix_format() {
53 echo "Fixing format..."
57 for f in ${files_to_lint}; do
58 whitelisted=$(awk '$1 == "'$f'" { print 1 }' "$CLANG_FORMAT_WHITELIST")
59 if [ -z "${whitelisted}" ]; then