From 877b5d1c1cedb9dc24cf1b77f06c1a1b0329238e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 15 Jan 2021 21:11:57 +0100 Subject: [PATCH 1/6] Add proper quotes in check_style.sh and report_errors.sh --- scripts/check_style.sh | 10 +++++----- scripts/report_errors.sh | 28 ++++++++++++++-------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/scripts/check_style.sh b/scripts/check_style.sh index 0ad19a6356f2..f0fae1eb6d19 100755 --- a/scripts/check_style.sh +++ b/scripts/check_style.sh @@ -14,7 +14,7 @@ EXCLUDE_FILES_JOINED=${EXCLUDE_FILES_JOINED%??} ( REPO_ROOT="$(dirname "$0")"/.. -cd $REPO_ROOT +cd "$REPO_ROOT" WHITESPACE=$(git grep -n -I -E "^.*[[:space:]]+$" | grep -v "test/libsolidity/ASTJSON\|test/libsolidity/ASTRecoveryTests\|test/compilationTests/zeppelin/LICENSE\|${EXCLUDE_FILES_JOINED}" @@ -22,8 +22,8 @@ WHITESPACE=$(git grep -n -I -E "^.*[[:space:]]+$" | if [[ "$WHITESPACE" != "" ]] then - echo "Error: Trailing whitespace found:" | tee -a $ERROR_LOG - echo "$WHITESPACE" | tee -a $ERROR_LOG + echo "Error: Trailing whitespace found:" | tee -a "$ERROR_LOG" + echo "$WHITESPACE" | tee -a "$ERROR_LOG" scripts/report_errors.sh "$ERROR_LOG" exit 1 fi @@ -51,8 +51,8 @@ FORMATERROR=$( if [[ "$FORMATERROR" != "" ]] then - echo "Coding style error:" | tee -a $ERROR_LOG - echo "$FORMATERROR" | tee -a $ERROR_LOG + echo "Coding style error:" | tee -a "$ERROR_LOG" + echo "$FORMATERROR" | tee -a "$ERROR_LOG" scripts/report_errors.sh "$ERROR_LOG" exit 1 fi diff --git a/scripts/report_errors.sh b/scripts/report_errors.sh index c4e370758223..dc5c73df8d33 100755 --- a/scripts/report_errors.sh +++ b/scripts/report_errors.sh @@ -4,16 +4,16 @@ ERROR_LOG="$1" function report_error_to_github { - if [ -z $CIRCLE_PR_NUMBER ] + if [ -z "$CIRCLE_PR_NUMBER" ] then CIRCLE_PR_NUMBER="${CIRCLE_PULL_REQUEST//[^0-9]/}" fi - ERROR_MSG=$(cat $ERROR_LOG) + ERROR_MSG=$(cat "$ERROR_LOG") - echo $ERROR_MSG + echo "$ERROR_MSG" - if [ ! -z $CI ] + if [ ! -z "$CI" ] then echo "posting error message to github" post_error_to_github @@ -25,15 +25,15 @@ function post_error_to_github { GITHUB_API_URL="https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/issues/$CIRCLE_PR_NUMBER/comments" - ESCAPED_ERROR_MSG=$(cat -e $ERROR_LOG | sed 's/\\/\\\\/g' | sed 's/"/\\\"/g') + ESCAPED_ERROR_MSG=$(cat -e "$ERROR_LOG" | sed 's/\\/\\\\/g' | sed 's/"/\\\"/g') - FORMATTED_ERROR_MSG=$(echo $ESCAPED_ERROR_MSG | sed 's/\$/\\n/g' | tr -d '\n') + FORMATTED_ERROR_MSG=$(echo "$ESCAPED_ERROR_MSG" | sed 's/\$/\\n/g' | tr -d '\n') curl --request POST \ - --url $GITHUB_API_URL \ + --url "$GITHUB_API_URL" \ --header 'accept: application/vnd.github.v3+json' \ --header 'content-type: application/json' \ - -u stackenbotten:$GITHUB_ACCESS_TOKEN \ + -u "stackenbotten:$GITHUB_ACCESS_TOKEN" \ --data "{\"body\": \"There was an error when running \`$CIRCLE_JOB\` for commit \`$CIRCLE_SHA1\`:\n\`\`\`\n$FORMATTED_ERROR_MSG\n\`\`\`\nPlease check that your changes are working as intended.\"}" } @@ -41,22 +41,22 @@ function post_review_comment_to_github { GITHUB_API_URL="https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pulls/$CIRCLE_PR_NUMBER/comments" - sed -i 1d $ERROR_LOG + sed -i 1d "$ERROR_LOG" while read line do - ERROR_PATH=$(echo $line | grep -oE ".*\.cpp") - ERROR_LINE=$(echo $line | grep -oE "[0-9]*") + ERROR_PATH=$(echo "$line" | grep -oE ".*\.cpp") + ERROR_LINE=$(echo "$line" | grep -oE "[0-9]*") [[ $ERROR_PATH != "" ]] || { echo "ERROR: Error message does not contain file path."; exit 1; } [[ $ERROR_LINE != "" ]] || { echo "ERROR: Error message does not contain line number."; exit 1; } curl --request POST \ - --url $GITHUB_API_URL \ + --url "$GITHUB_API_URL" \ --header 'accept: application/vnd.github.v3+json, application/vnd.github.comfort-fade-preview+json' \ --header 'content-type: application/json' \ - -u stackenbotten:$GITHUB_ACCESS_TOKEN \ + -u "stackenbotten:$GITHUB_ACCESS_TOKEN" \ --data "{\"commit_id\": \"$CIRCLE_SHA1\", \"path\": \"$ERROR_PATH\", \"line\": $ERROR_LINE, \"side\": \"RIGHT\", \"body\": \"Coding style error\"}" - done < $ERROR_LOG + done < "$ERROR_LOG" } report_error_to_github From e5bc08fa7ba5e5e6b71d1f938f6591cb4a58c819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 15 Jan 2021 21:12:19 +0100 Subject: [PATCH 2/6] Fix shellcheck errors in report_errors.sh and check_style.sh --- scripts/check_style.sh | 10 +++++----- scripts/chk_shellscripts/ignore.txt | 2 -- scripts/report_errors.sh | 6 +++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/scripts/check_style.sh b/scripts/check_style.sh index f0fae1eb6d19..a5d9ec3c6844 100755 --- a/scripts/check_style.sh +++ b/scripts/check_style.sh @@ -14,7 +14,7 @@ EXCLUDE_FILES_JOINED=${EXCLUDE_FILES_JOINED%??} ( REPO_ROOT="$(dirname "$0")"/.. -cd "$REPO_ROOT" +cd "$REPO_ROOT" || exit 1 WHITESPACE=$(git grep -n -I -E "^.*[[:space:]]+$" | grep -v "test/libsolidity/ASTJSON\|test/libsolidity/ASTRecoveryTests\|test/compilationTests/zeppelin/LICENSE\|${EXCLUDE_FILES_JOINED}" @@ -36,17 +36,17 @@ function preparedGrep() FORMATERROR=$( ( - preparedGrep "#include \"" | egrep -v -e "license.h" -e "BuildInfo.h" # Use include with <> characters + preparedGrep "#include \"" | grep -E -v -e "license.h" -e "BuildInfo.h" # Use include with <> characters preparedGrep "\<(if|for|while|switch)\(" # no space after "if", "for", "while" or "switch" preparedGrep "\\s*\([^=]*\>\s:\s.*\)" # no space before range based for-loop preparedGrep "\\s*\(.*\)\s*\{\s*$" # "{\n" on same line as "if" / "for" preparedGrep "[,\(<]\s*const " # const on left side of type preparedGrep "^\s*(static)?\s*const " # const on left side of type (beginning of line) preparedGrep "^ [^*]|[^*] | [^*]" # uses spaces for indentation or mixes spaces and tabs - preparedGrep "[a-zA-Z0-9_]\s*[&][a-zA-Z_]" | egrep -v "return [&]" # right-aligned reference ampersand (needs to exclude return) + preparedGrep "[a-zA-Z0-9_]\s*[&][a-zA-Z_]" | grep -E -v "return [&]" # right-aligned reference ampersand (needs to exclude return) # right-aligned reference pointer star (needs to exclude return and comments) - preparedGrep "[a-zA-Z0-9_]\s*[*][a-zA-Z_]" | egrep -v -e "return [*]" -e "^* [*]" -e "^*//.*" -) | egrep -v -e "^[a-zA-Z\./]*:[0-9]*:\s*\/(\/|\*)" -e "^test/" + preparedGrep "[a-zA-Z0-9_]\s*[*][a-zA-Z_]" | grep -E -v -e "return [*]" -e "^* [*]" -e "^*//.*" +) | grep -E -v -e "^[a-zA-Z\./]*:[0-9]*:\s*\/(\/|\*)" -e "^test/" ) if [[ "$FORMATERROR" != "" ]] diff --git a/scripts/chk_shellscripts/ignore.txt b/scripts/chk_shellscripts/ignore.txt index 188efb0ab5ff..aaf01948dacc 100644 --- a/scripts/chk_shellscripts/ignore.txt +++ b/scripts/chk_shellscripts/ignore.txt @@ -14,7 +14,6 @@ ./scripts/docker_build.sh ./scripts/docs_version_pragma_check.sh ./scripts/uniqueErrors.sh -./scripts/report_errors.sh ./scripts/tests.sh ./scripts/docker_deploy.sh ./scripts/bytecodecompare/storebytecode.sh @@ -24,7 +23,6 @@ ./scripts/install_obsolete_jsoncpp_1_7_4.sh ./scripts/install_deps.sh ./scripts/build.sh -./scripts/check_style.sh ./scripts/run_proofs.sh ./scripts/common_cmdline.sh ./scripts/docker_deploy_manual.sh diff --git a/scripts/report_errors.sh b/scripts/report_errors.sh index dc5c73df8d33..fbdf9f958cb8 100755 --- a/scripts/report_errors.sh +++ b/scripts/report_errors.sh @@ -4,7 +4,7 @@ ERROR_LOG="$1" function report_error_to_github { - if [ -z "$CIRCLE_PR_NUMBER" ] + if [[ $CIRCLE_PR_NUMBER != "" ]] then CIRCLE_PR_NUMBER="${CIRCLE_PULL_REQUEST//[^0-9]/}" fi @@ -13,7 +13,7 @@ function report_error_to_github echo "$ERROR_MSG" - if [ ! -z "$CI" ] + if [[ $CI == "true" ]] then echo "posting error message to github" post_error_to_github @@ -43,7 +43,7 @@ function post_review_comment_to_github sed -i 1d "$ERROR_LOG" - while read line + while read -r line do ERROR_PATH=$(echo "$line" | grep -oE ".*\.cpp") ERROR_LINE=$(echo "$line" | grep -oE "[0-9]*") From 0a3cc816934db3a7735ce89c47b4d6580735313d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 15 Jan 2021 21:19:58 +0100 Subject: [PATCH 3/6] check_style.sh: Consistent identation --- scripts/check_style.sh | 52 +++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/scripts/check_style.sh b/scripts/check_style.sh index a5d9ec3c6844..664e84eac332 100755 --- a/scripts/check_style.sh +++ b/scripts/check_style.sh @@ -3,11 +3,11 @@ ERROR_LOG="$(mktemp -t check_style_XXXXXX.log)" EXCLUDE_FILES=( - "libsolutil/picosha2.h" - "test/libsolutil/UTF8.cpp" - "test/libsolidity/syntaxTests/license/license_cr_endings.sol" - "test/libsolidity/syntaxTests/license/license_crlf_endings.sol" - "test/libsolidity/syntaxTests/license/license_whitespace_trailing.sol" + "libsolutil/picosha2.h" + "test/libsolutil/UTF8.cpp" + "test/libsolidity/syntaxTests/license/license_cr_endings.sol" + "test/libsolidity/syntaxTests/license/license_crlf_endings.sol" + "test/libsolidity/syntaxTests/license/license_whitespace_trailing.sol" ) EXCLUDE_FILES_JOINED=$(printf "%s\|" "${EXCLUDE_FILES[@]}") EXCLUDE_FILES_JOINED=${EXCLUDE_FILES_JOINED%??} @@ -17,43 +17,43 @@ REPO_ROOT="$(dirname "$0")"/.. cd "$REPO_ROOT" || exit 1 WHITESPACE=$(git grep -n -I -E "^.*[[:space:]]+$" | - grep -v "test/libsolidity/ASTJSON\|test/libsolidity/ASTRecoveryTests\|test/compilationTests/zeppelin/LICENSE\|${EXCLUDE_FILES_JOINED}" + grep -v "test/libsolidity/ASTJSON\|test/libsolidity/ASTRecoveryTests\|test/compilationTests/zeppelin/LICENSE\|${EXCLUDE_FILES_JOINED}" ) if [[ "$WHITESPACE" != "" ]] then - echo "Error: Trailing whitespace found:" | tee -a "$ERROR_LOG" - echo "$WHITESPACE" | tee -a "$ERROR_LOG" - scripts/report_errors.sh "$ERROR_LOG" - exit 1 + echo "Error: Trailing whitespace found:" | tee -a "$ERROR_LOG" + echo "$WHITESPACE" | tee -a "$ERROR_LOG" + scripts/report_errors.sh "$ERROR_LOG" + exit 1 fi function preparedGrep() { - git grep -nIE "$1" -- '*.h' '*.cpp' | grep -v "${EXCLUDE_FILES_JOINED}" - return $? + git grep -nIE "$1" -- '*.h' '*.cpp' | grep -v "${EXCLUDE_FILES_JOINED}" + return $? } FORMATERROR=$( ( - preparedGrep "#include \"" | grep -E -v -e "license.h" -e "BuildInfo.h" # Use include with <> characters - preparedGrep "\<(if|for|while|switch)\(" # no space after "if", "for", "while" or "switch" - preparedGrep "\\s*\([^=]*\>\s:\s.*\)" # no space before range based for-loop - preparedGrep "\\s*\(.*\)\s*\{\s*$" # "{\n" on same line as "if" / "for" - preparedGrep "[,\(<]\s*const " # const on left side of type - preparedGrep "^\s*(static)?\s*const " # const on left side of type (beginning of line) - preparedGrep "^ [^*]|[^*] | [^*]" # uses spaces for indentation or mixes spaces and tabs - preparedGrep "[a-zA-Z0-9_]\s*[&][a-zA-Z_]" | grep -E -v "return [&]" # right-aligned reference ampersand (needs to exclude return) - # right-aligned reference pointer star (needs to exclude return and comments) - preparedGrep "[a-zA-Z0-9_]\s*[*][a-zA-Z_]" | grep -E -v -e "return [*]" -e "^* [*]" -e "^*//.*" + preparedGrep "#include \"" | grep -E -v -e "license.h" -e "BuildInfo.h" # Use include with <> characters + preparedGrep "\<(if|for|while|switch)\(" # no space after "if", "for", "while" or "switch" + preparedGrep "\\s*\([^=]*\>\s:\s.*\)" # no space before range based for-loop + preparedGrep "\\s*\(.*\)\s*\{\s*$" # "{\n" on same line as "if" / "for" + preparedGrep "[,\(<]\s*const " # const on left side of type + preparedGrep "^\s*(static)?\s*const " # const on left side of type (beginning of line) + preparedGrep "^ [^*]|[^*] | [^*]" # uses spaces for indentation or mixes spaces and tabs + preparedGrep "[a-zA-Z0-9_]\s*[&][a-zA-Z_]" | grep -E -v "return [&]" # right-aligned reference ampersand (needs to exclude return) + # right-aligned reference pointer star (needs to exclude return and comments) + preparedGrep "[a-zA-Z0-9_]\s*[*][a-zA-Z_]" | grep -E -v -e "return [*]" -e "^* [*]" -e "^*//.*" ) | grep -E -v -e "^[a-zA-Z\./]*:[0-9]*:\s*\/(\/|\*)" -e "^test/" ) if [[ "$FORMATERROR" != "" ]] then - echo "Coding style error:" | tee -a "$ERROR_LOG" - echo "$FORMATERROR" | tee -a "$ERROR_LOG" - scripts/report_errors.sh "$ERROR_LOG" - exit 1 + echo "Coding style error:" | tee -a "$ERROR_LOG" + echo "$FORMATERROR" | tee -a "$ERROR_LOG" + scripts/report_errors.sh "$ERROR_LOG" + exit 1 fi ) From f214682a27a1cff355a1e0adbf58610d53bdf8fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 15 Jan 2021 21:20:34 +0100 Subject: [PATCH 4/6] report_errors.sh: Don't print error messages to stdout - check_style.sh already does this --- scripts/report_errors.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/report_errors.sh b/scripts/report_errors.sh index fbdf9f958cb8..cfc0b5bf09e7 100755 --- a/scripts/report_errors.sh +++ b/scripts/report_errors.sh @@ -9,10 +9,6 @@ function report_error_to_github CIRCLE_PR_NUMBER="${CIRCLE_PULL_REQUEST//[^0-9]/}" fi - ERROR_MSG=$(cat "$ERROR_LOG") - - echo "$ERROR_MSG" - if [[ $CI == "true" ]] then echo "posting error message to github" From 7bc81e3c95016165f776bba1193c2ef4b1d58954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 15 Jan 2021 21:51:11 +0100 Subject: [PATCH 5/6] Rename report_errors.sh to post_style_errors_on_github.sh --- scripts/check_style.sh | 4 ++-- .../{report_errors.sh => ci/post_style_errors_on_github.sh} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename scripts/{report_errors.sh => ci/post_style_errors_on_github.sh} (100%) diff --git a/scripts/check_style.sh b/scripts/check_style.sh index 664e84eac332..870ea0234297 100755 --- a/scripts/check_style.sh +++ b/scripts/check_style.sh @@ -24,7 +24,7 @@ if [[ "$WHITESPACE" != "" ]] then echo "Error: Trailing whitespace found:" | tee -a "$ERROR_LOG" echo "$WHITESPACE" | tee -a "$ERROR_LOG" - scripts/report_errors.sh "$ERROR_LOG" + scripts/post_style_errors_on_github.sh "$ERROR_LOG" exit 1 fi @@ -53,7 +53,7 @@ if [[ "$FORMATERROR" != "" ]] then echo "Coding style error:" | tee -a "$ERROR_LOG" echo "$FORMATERROR" | tee -a "$ERROR_LOG" - scripts/report_errors.sh "$ERROR_LOG" + scripts/post_style_errors_on_github.sh "$ERROR_LOG" exit 1 fi ) diff --git a/scripts/report_errors.sh b/scripts/ci/post_style_errors_on_github.sh similarity index 100% rename from scripts/report_errors.sh rename to scripts/ci/post_style_errors_on_github.sh From 81f3c7497b2f3fcae6899df80f3d0d8af45a3268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Fri, 15 Jan 2021 22:07:08 +0100 Subject: [PATCH 6/6] check_style.sh: Fix incorrect comment about `for {` being treated as a style error --- scripts/check_style.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_style.sh b/scripts/check_style.sh index 870ea0234297..610edc3ff4f0 100755 --- a/scripts/check_style.sh +++ b/scripts/check_style.sh @@ -39,7 +39,7 @@ FORMATERROR=$( preparedGrep "#include \"" | grep -E -v -e "license.h" -e "BuildInfo.h" # Use include with <> characters preparedGrep "\<(if|for|while|switch)\(" # no space after "if", "for", "while" or "switch" preparedGrep "\\s*\([^=]*\>\s:\s.*\)" # no space before range based for-loop - preparedGrep "\\s*\(.*\)\s*\{\s*$" # "{\n" on same line as "if" / "for" + preparedGrep "\\s*\(.*\)\s*\{\s*$" # "{\n" on same line as "if" preparedGrep "[,\(<]\s*const " # const on left side of type preparedGrep "^\s*(static)?\s*const " # const on left side of type (beginning of line) preparedGrep "^ [^*]|[^*] | [^*]" # uses spaces for indentation or mixes spaces and tabs