add validation tools

This commit is contained in:
keita
2021-02-16 15:10:56 +09:00
parent 6fa7c457c0
commit f99ffa71b8
5 changed files with 67 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
Language: Cpp
BasedOnStyle: Google
AccessModifierOffset: -2
AlignConsecutiveAssignments: true
AllowShortFunctionsOnASingleLine: Empty
ColumnLimit: 96
Cpp11BracedListStyle: true
DerivePointerAlignment: false
SortIncludes: false
SpacesBeforeTrailingComments: 1
Standard: Cpp11
+8
View File
@@ -0,0 +1,8 @@
#!/bin/bash
. "$(dirname "$0")/isTopLevel.sh"
for f in $(git ls-files | grep -E '.*\.(cc|h)$'); do
echo "formatting ${f}"
clang-format -i "${f}"
done
+9
View File
@@ -0,0 +1,9 @@
#!/bin/bash
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
exit 1
fi
if [ "$(pwd)" != "$(git rev-parse --show-toplevel)" ]; then
exit 1
fi
+14
View File
@@ -0,0 +1,14 @@
#!/bin/bash
. "$(dirname "$0")/../isTopLevel.sh"
RETVAL=0
for f in $(git ls-files | grep -E '.*\.(cc|h)$'); do
if ! clang-format "${f}" | diff "${f}" - > /dev/null 2>&1; then
echo "Error: Invalid code formatting in ${f}" >&2
RETVAL=1
fi
done
exit $RETVAL
+25
View File
@@ -0,0 +1,25 @@
#!/bin/bash
. "$(dirname "$0")/../isTopLevel.sh"
RETVAL=0
for f in $(git ls-files | grep -E '^src\/.*\.h$'); do
# ファイルパスから正しいインクルードガードの文字列を生成する
s1="$(echo "$f" | sed -r 's/^src\///; s/[\/\.-]+/_/g; s/^.*$/\U&/')_"
# ファイルからインクルードガードを読み込む
s2=$(grep -Pzo '#ifndef\s+\K\b(\w+)\b(?=\s+#define\s+\b\1\b)' "$f" | tr '\0' '\n')
if [ -z "$s2" ]; then
echo "error: $f: include guard is missing or incorrect" >&2
echo " ($s1)" >&2
RETVAL=1
elif [ "$s2" != "$s1" ]; then
echo "error: $f: include guard is incorrect" >&2
echo " ($s2 => $s1)" >&2
RETVAL=1
fi
done
exit $RETVAL