@@ -25,60 +25,64 @@ EXCLUDE_FILES_JOINED=${EXCLUDE_FILES_JOINED%??}
2525REPO_ROOT=" $( dirname " $0 " ) " /..
2626cd " $REPO_ROOT " || exit 1
2727
28+ function preparedGrep
29+ {
30+ git grep -nIE " $1 " -- ' *.h' ' *.cpp' ' :!test/' | grep -v " ${EXCLUDE_FILES_JOINED} "
31+ return $?
32+ }
33+
34+ function addPrefix
35+ {
36+ sed " s/^/[$1 ] /"
37+ }
38+
2839WHITESPACE=$( git grep -n -I -E " ^.*[[:space:]]+$" |
2940 grep -v " test/libsolidity/ASTJSON\|test/compilationTests/zeppelin/LICENSE\|${EXCLUDE_FILES_JOINED} " || true
3041)
3142
3243if [[ " $WHITESPACE " != " " ]]
3344then
3445 echo " Error: Trailing whitespace found:" | tee -a " $ERROR_LOG "
35- echo " $WHITESPACE " | tee -a " $ERROR_LOG "
36- scripts/ci/post_style_errors_on_github.sh " $ERROR_LOG "
37- exit 1
46+ echo " $WHITESPACE " | addPrefix " Trailing whitespace" | tee -a " $ERROR_LOG "
3847fi
3948
40- function preparedGrep
41- {
42- git grep -nIE " $1 " -- ' *.h' ' *.cpp' | grep -v " ${EXCLUDE_FILES_JOINED} "
43- return $?
44- }
45-
4649FORMATERROR=$(
4750(
48- preparedGrep " #include \" " | grep -E -v -e " license.h" -e " BuildInfo.h" # Use include with <> characters
49- preparedGrep " \<(if|for|while|switch)\(" # no space after "if", "for", "while" or "switch"
50- preparedGrep " \<for\>[[:space:]]*\([^=]*\>[[:space:]]:[[:space:]].*\)" # no space before range based for-loop
51- preparedGrep " \<if\>[[:space:]]*\(.*\)[[:space:]]*\{[[:space:]]*$" # "{\n" on same line as "if"
52- preparedGrep " namespace .*\{"
53- preparedGrep " [,\(<][[:space:]]*const " # const on left side of type
54- preparedGrep " ^[[:space:]]*(static)?[[:space:]]*const " # const on left side of type (beginning of line)
55- preparedGrep " ^ [^*]|[^*] | [^*]" # uses spaces for indentation or mixes spaces and tabs
56- preparedGrep " [a-zA-Z0-9_][[:space:]]*[&][a-zA-Z_]" | grep -E -v " return [&]" # right-aligned reference ampersand (needs to exclude return)
57- # right-aligned reference pointer star (needs to exclude return and comments)
58- preparedGrep " [a-zA-Z0-9_][[:space:]]*[*][a-zA-Z_]" | grep -E -v -e " return [*]" -e " :[0-9]+:[[:space:]]*\*[[:space:]]" -e " //"
59- # unqualified move()/forward() checks, i.e. make sure that std::move() and std::forward() are used instead of move() and forward()
60- preparedGrep " move\(.+\)" | grep -v " std::move" | grep -E " [^a-z]move"
61- preparedGrep " forward\(.+\)" | grep -v " std::forward" | grep -E " [^a-z]forward"
62- ) | grep -E -v -e " ^[a-zA-Z./]*:[0-9]*:[[:space:]]*/[/*]" -e " ^test/" || true
51+ preparedGrep " #include \" " | grep -E -v -e " license.h" -e " BuildInfo.h" | addPrefix " Use angle brackets for includes"
52+ preparedGrep " \<(if|for|while|switch)\(" | addPrefix " Missing space after keyword"
53+ preparedGrep " \<for\>[[:space:]]*\([^=]*\>[[:space:]]:[[:space:]].*\)" | addPrefix " Missing space before range-based for colon"
54+ preparedGrep " \<if\>[[:space:]]*\(.*\)[[:space:]]*\{[[:space:]]*$" | addPrefix " Opening brace on same line as if"
55+ preparedGrep " namespace .*\{" | addPrefix " Missing space before opening brace in namespace"
56+ preparedGrep " [,\(<][[:space:]]*const " | addPrefix " const should be on the right side of the type"
57+ preparedGrep " ^[[:space:]]*(static)?[[:space:]]*const " | addPrefix " const should be on the right side of the type"
58+ preparedGrep " ^ [^*]|[^*] | [^*]" | addPrefix " Use tabs for indentation"
59+ preparedGrep " [a-zA-Z0-9_][[:space:]]*[&][a-zA-Z_]" | grep -E -v " return [&]" | addPrefix " Reference ampersand should be left-aligned"
60+ preparedGrep " [a-zA-Z0-9_][[:space:]]*[*][a-zA-Z_]" | grep -E -v -e " return [*]" -e " :[0-9]+:[[:space:]]*\*[[:space:]]" -e " //" | addPrefix " Pointer star should be left-aligned"
61+ preparedGrep " move\(.+\)" | grep -v " std::move" | grep -E " [^a-z]move" | addPrefix " Use std::move"
62+ preparedGrep " forward\(.+\)" | grep -v " std::forward" | grep -E " [^a-z]forward" | addPrefix " Use std::forward"
63+ ) | grep -E -v -e " ^\[[^]]*\] [a-zA-Z./]*:[0-9]*:[[:space:]]*/[/*]" || true
6364)
6465
6566# Special error handling for `using namespace std;` exclusion, since said statement can be present in the test directory
6667# and its subdirectories, but is excluded in the above ruleset. In order to have consistent codestyle with regards to
6768# std namespace usage, test directory must also be covered.
6869FORMATSTDERROR=$(
6970(
70- git grep -nIE " using namespace std;" -- ' *.h' ' *.cpp'
71+ git grep -nIE " using namespace std;" -- ' *.h' ' *.cpp' | addPrefix " Do not use 'using namespace std' "
7172) || true
7273)
7374
7475# Merge errors into single string
75- FORMATEDERRORS=" $FORMATERROR$FORMATSTDERROR "
76+ FORMATEDERRORS=$( printf ' %s\n ' " $FORMATERROR " " $FORMATSTDERROR " | grep -v ' ^$ ' || true )
7677
7778if [[ " $FORMATEDERRORS " != " " ]]
7879then
7980 echo " Coding style error:" | tee -a " $ERROR_LOG "
8081 echo " $FORMATEDERRORS " | tee -a " $ERROR_LOG "
81- scripts/ci/post_style_errors_on_github.sh " $ERROR_LOG "
82+ fi
83+
84+ if [[ -s " $ERROR_LOG " ]]
85+ then
8286 exit 1
8387fi
8488)
0 commit comments