diff --git a/scripts/check_style.sh b/scripts/check_style.sh index 0ad19a635..f0fae1eb6 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 c4e370758..dc5c73df8 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