Skip to content

Commit

Permalink
Additionally do clang check (with exit 0/1)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonmavr committed Feb 15, 2022
1 parent ae857f5 commit ba7c1d2
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions scripts/clang_format.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/bin/bash

# This script formats the spacings in your code according
# to clang's standards
### Instructions:
# Run as ./clang_format.sh --test to test if all source files
# are properly formatted
# Run with any other way or with no arguments to format them
### Requirements:
# clang-format

which clang-format > /dev/null 2>&1
if [ $? -ne 0 ]; then
Expand All @@ -12,6 +16,21 @@ fi

script_dir=`cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd`
declare -a src_files=($script_dir/../main.cpp $script_dir/../include/*.hpp $script_dir/../src/*.cpp)
for s in "${src_files[@]}"; do
clang-format -i $s
done
if [ "$*" == --test ]; then
tmp_src_file=`mktemp`
for s in "${src_files[@]}"; do
clang-format "$s" > $tmp_src_file
if [[ `diff $s $tmp_src_file` != "" ]]; then
echo -e "This repo uses clang spacing standards.\n"\
"Please run ./scripts/clang_format.sh to format "\
"all source files. Exiting..."
rm $tmp_src_file
exit 1
fi
done
rm $tmp_src_file
else
for s in "${src_files[@]}"; do
clang-format -i "$s"
done
fi

0 comments on commit ba7c1d2

Please sign in to comment.