From 90d1b838ad2d90b25936b746c44db283b68956a2 Mon Sep 17 00:00:00 2001 From: Piotr Tabor Date: Fri, 29 Jan 2021 22:31:44 +0000 Subject: [PATCH] Fix shellcheck warnings: Escaping. ``` build:3:65: note: Backslash is literal in "\n". Prefer explicit escaping: "\\n". [SC1117] test:3:64: note: Backslash is literal in "\n". Prefer explicit escaping: "\\n". [SC1117] scripts/fix.sh:23:17: note: Backslash is literal in "\n". Prefer explicit escaping: "\\n". [SC1117] scripts/fix.sh:23:46: note: Backslash is literal in "\n". Prefer explicit escaping: "\\n". [SC1117] scripts/fix.sh:30:17: note: Backslash is literal in "\n". Prefer explicit escaping: "\\n". [SC1117] scripts/genproto.sh:38:17: note: Backslash is literal in "\n". Prefer explicit escaping: "\\n". [SC1117] scripts/genproto.sh:53:17: note: Backslash is literal in "\n". Prefer explicit escaping: "\\n". [SC1117] scripts/genproto.sh:73:23: note: Backslash is literal in "\(". Prefer explicit escaping: "\\(". [SC1117] scripts/genproto.sh:73:33: note: Backslash is literal in "\(". Prefer explicit escaping: "\\(". [SC1117] scripts/genproto.sh:74:69: note: Backslash is literal in "\1". Prefer explicit escaping: "\\1". [SC1117] scripts/genproto.sh:74:78: note: Backslash is literal in "\2". Prefer explicit escaping: "\\2". [SC1117] scripts/genproto.sh:75:40: note: Backslash is literal in "\(". Prefer explicit escaping: "\\(". [SC1117] scripts/genproto.sh:75:52: note: Backslash is literal in "\1". Prefer explicit escaping: "\\1". [SC1117] scripts/genproto.sh:91:17: note: Backslash is literal in "\n". Prefer explicit escaping: "\\n". [SC1117] scripts/genproto.sh:115:17: note: Backslash is literal in "\n". Prefer explicit escaping: "\\n". [SC1117] ./test.sh:71:29: warning: Quote to prevent word splitting, or split robustly with mapfile or read -a. [SC2206] ./test.sh:400:28: note: Backslash is literal in "\t". Prefer explicit escaping: "\\t". [SC1117] ./test.sh:406:33: note: Backslash is literal in "\t". Prefer explicit escaping: "\\t". [SC1117] ./test.sh:415:36: note: Backslash is literal in "\*". Prefer explicit escaping: "\\*". [SC1117] ./test.sh:415:176: note: Backslash is literal in "\'". Prefer explicit escaping: "\\'". [SC1117] ./test.sh:493:56: note: Backslash is literal in "\.". Prefer explicit escaping: "\\.". [SC1117] ./test.sh:601:57: note: Backslash is literal in "\(". Prefer explicit escaping: "\\(". [SC1117] ./test.sh:601:64: note: Backslash is literal in "\)". Prefer explicit escaping: "\\)". [SC1117] ./test.sh:601:67: note: Backslash is literal in "\(". Prefer explicit escaping: "\\(". [SC1117] ./test.sh:601:74: note: Backslash is literal in "\)". Prefer explicit escaping: "\\)". [SC1117] ./test.sh:601:77: note: Backslash is literal in "\(". Prefer explicit escaping: "\\(". [SC1117] ./test.sh:601:84: note: Backslash is literal in "\)". Prefer explicit escaping: "\\)". [SC1117] ./test.sh:601:91: note: Backslash is literal in "\1". Prefer explicit escaping: "\\1". [SC1117] ./test.sh:601:94: note: Backslash is literal in "\2". Prefer explicit escaping: "\\2". [SC1117] ./test.sh:601:103: note: Backslash is literal in "\3". Prefer explicit escaping: "\\3". [SC1117] ``` --- build | 2 +- scripts/fix.sh | 4 ++-- scripts/genproto.sh | 14 +++++++------- scripts/test_lib.sh | 6 +++--- test | 2 +- test.sh | 27 ++++++++++++++------------- 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/build b/build index b9e031074..60aa15d76 100755 --- a/build +++ b/build @@ -1,6 +1,6 @@ #!/usr/bin/env bash -echo -e "\e[91mDEPRECATED!!! Use build.sh script instead.\e[0m\n" +echo -e "\\e[91mDEPRECATED!!! Use build.sh script instead.\\e[0m\\n" sleep 1 source ./build.sh diff --git a/scripts/fix.sh b/scripts/fix.sh index c512444b4..4e10f44a9 100755 --- a/scripts/fix.sh +++ b/scripts/fix.sh @@ -20,11 +20,11 @@ function bash_ws_fix { find ./ -name '*.sh.bak' -print0 | xargs -0 rm } -log_callout -e "\nFixing etcd code for you...\n" +log_callout -e "\\nFixing etcd code for you...\\n" run_for_modules run go fmt || exit 2 run_for_modules mod_tidy_fix || exit 2 run_for_module tests bom_fix || exit 2 bash_ws_fix || exit 2 -log_success -e "\nSUCCESS: etcd code is fixed :)" +log_success -e "\\nSUCCESS: etcd code is fixed :)" diff --git a/scripts/genproto.sh b/scripts/genproto.sh index d8c5b6052..dd036d120 100755 --- a/scripts/genproto.sh +++ b/scripts/genproto.sh @@ -35,7 +35,7 @@ GOGOPROTO_PATH="${GOGOPROTO_ROOT}:${GOGOPROTO_ROOT}/protobuf" # directories containing protos to be built DIRS="./server/wal/walpb ./api/etcdserverpb ./server/etcdserver/api/snap/snappb ./raft/raftpb ./api/mvccpb ./server/lease/leasepb ./api/authpb ./server/etcdserver/api/v3lock/v3lockpb ./server/etcdserver/api/v3election/v3electionpb ./api/membershippb" -log_callout -e "\nRunning gofast (gogo) proto generation..." +log_callout -e "\\nRunning gofast (gogo) proto generation..." for dir in ${DIRS}; do run pushd "${dir}" @@ -50,7 +50,7 @@ for dir in ${DIRS}; do run popd done -log_callout -e "\nRunning swagger & grpc_gateway proto generation..." +log_callout -e "\\nRunning swagger & grpc_gateway proto generation..." # remove old swagger files so it's obvious whether the files fail to generate rm -rf Documentation/dev-guide/apispec/swagger/*json @@ -70,9 +70,9 @@ for pb in api/etcdserverpb/rpc server/etcdserver/api/v3lock/v3lockpb/v3lock serv gwfile="${pb}.pb.gw.go" sed -i -E "s#package $pkg#package gw#g" "${gwfile}" - sed -i -E "s#import \(#import \(\"go.etcd.io/etcd/${pkgpath}\"#g" "${gwfile}" - sed -i -E "s#([ (])([a-zA-Z0-9_]*(Client|Server|Request)([^(]|$))#\1${pkg}.\2#g" "${gwfile}" - sed -i -E "s# (New[a-zA-Z0-9_]*Client\()# ${pkg}.\1#g" "${gwfile}" + sed -i -E "s#import \\(#import \\(\"go.etcd.io/etcd/${pkgpath}\"#g" "${gwfile}" + sed -i -E "s#([ (])([a-zA-Z0-9_]*(Client|Server|Request)([^(]|$))#\\1${pkg}.\\2#g" "${gwfile}" + sed -i -E "s# (New[a-zA-Z0-9_]*Client\\()# ${pkg}.\\1#g" "${gwfile}" sed -i -E "s|go.etcd.io/etcd|go.etcd.io/etcd/v3|g" "${gwfile}" sed -i -E "s|go.etcd.io/etcd/v3/api|go.etcd.io/etcd/api/v3|g" "${gwfile}" sed -i -E "s|go.etcd.io/etcd/v3/server|go.etcd.io/etcd/server/v3|g" "${gwfile}" @@ -88,7 +88,7 @@ for pb in api/etcdserverpb/rpc server/etcdserver/api/v3lock/v3lockpb/v3lock serv Documentation/dev-guide/apispec/swagger/"${swaggerName}".swagger.json done -log_callout -e "\nRunning swagger ..." +log_callout -e "\\nRunning swagger ..." run_go_tool github.com/hexfusion/schwag -input=Documentation/dev-guide/apispec/swagger/rpc.swagger.json if [ "$1" != "--skip-protodoc" ]; then @@ -112,4 +112,4 @@ else log_warning "skipping grpc API reference document auto-generation..." fi -log_success -e "\n./genproto SUCCESS" +log_success -e "\\n./genproto SUCCESS" diff --git a/scripts/test_lib.sh b/scripts/test_lib.sh index 984689d62..90844cea2 100644 --- a/scripts/test_lib.sh +++ b/scripts/test_lib.sh @@ -146,7 +146,7 @@ function run { "${@}" 2> >(while read -r line; do echo -e "${COLOR_NONE}stderr: ${COLOR_MAGENTA}${line}${COLOR_NONE}">&2; done) local error_code=$? if [ ${error_code} -ne 0 ]; then - log_error -e "FAIL: (code:${error_code}):\n % ${repro}" + log_error -e "FAIL: (code:${error_code}):\\n % ${repro}" return ${error_code} fi } @@ -170,7 +170,7 @@ function module_dirs() { # maybe_run [cmd...] runs given command depending on the DRY_RUN flag. function maybe_run() { if ${DRY_RUN}; then - log_warning -e "# DRY_RUN:\n % ${*}" + log_warning -e "# DRY_RUN:\\n % ${*}" else run "${@}" fi @@ -280,7 +280,7 @@ function go_test { done if [ -n "${failures[*]}" ] ; then - log_error -e "ERROR: Tests for following packages failed:\n ${failures[*]}" + log_error -e "ERROR: Tests for following packages failed:\\n ${failures[*]}" return 2 fi } diff --git a/test b/test index e47fcb6ef..a14782bc3 100755 --- a/test +++ b/test @@ -1,6 +1,6 @@ #!/usr/bin/env bash -echo -e "\e[91mDEPRECATED!!! Use test.sh script instead.\e[0m\n" +echo -e "\\e[91mDEPRECATED!!! Use test.sh script instead.\\e[0m\\n" sleep 1 source ./test.sh diff --git a/test.sh b/test.sh index d71be564f..06137b9eb 100755 --- a/test.sh +++ b/test.sh @@ -68,7 +68,7 @@ fi # This options make sense for cases where SUT (System Under Test) is compiled by test. COMMON_TEST_FLAGS=("${RACE}") if [[ ! -z "${CPU}" ]]; then - COMMON_TEST_FLAGS+=(--cpu ${CPU}) + COMMON_TEST_FLAGS+=("--cpu=${CPU}") fi log_callout "Running with ${COMMON_TEST_FLAGS[*]}" @@ -174,13 +174,13 @@ function functional_pass { kill -s TERM "${agent_pids[@]}" || true if [[ "${etcd_tester_exit_code}" -ne "0" ]]; then - log_error -e "\nFAILED! 'tail -1000 /tmp/etcd-functional-1/etcd.log'" + log_error -e "\\nFAILED! 'tail -1000 /tmp/etcd-functional-1/etcd.log'" tail -1000 /tmp/etcd-functional-1/etcd.log - log_error -e "\nFAILED! 'tail -1000 /tmp/etcd-functional-2/etcd.log'" + log_error -e "\\nFAILED! 'tail -1000 /tmp/etcd-functional-2/etcd.log'" tail -1000 /tmp/etcd-functional-2/etcd.log - log_error -e "\nFAILED! 'tail -1000 /tmp/etcd-functional-3/etcd.log'" + log_error -e "\\nFAILED! 'tail -1000 /tmp/etcd-functional-3/etcd.log'" tail -1000 /tmp/etcd-functional-3/etcd.log log_error "--- FAIL: exit code" ${etcd_tester_exit_code} @@ -392,18 +392,19 @@ function shellcheck_pass { } function shellws_pass { + TAB=$'\t' log_callout "Ensuring no tab-based indention in shell scripts" local files files=$(find ./ -name '*.sh' -print0 | xargs -0 ) # shellcheck disable=SC2206 files=( ${files[@]} "./scripts/build-binary" "./scripts/build-docker" "./scripts/release" ) - log_cmd "grep -E -n $'^ *\t' ${files[*]}" + log_cmd "grep -E -n $'^ *${TAB}' ${files[*]}" # shellcheck disable=SC2086 - if grep -E -n $'^ *\t' "${files[@]}" | sed $'s|\t|[\\\\tab]|g'; then + if grep -E -n $'^ *${TAB}' "${files[@]}" | sed $'s|${TAB}|[\\\\tab]|g'; then log_error "FAIL: found tab-based indention in bash scripts. Use ' ' (double space)." local files_with_tabs - files_with_tabs=$(grep -E -l $'^ *\t' "${files[@]}") - log_warning "Try: sed -i 's|\t| |g' $files_with_tabs" + files_with_tabs=$(grep -E -l $'^ *\\t' "${files[@]}") + log_warning "Try: sed -i 's|\\t| |g' $files_with_tabs" return 1 else log_success "SUCCESS: no tabulators found." @@ -412,7 +413,7 @@ function shellws_pass { } function markdown_you_find_eschew_you { - local find_you_cmd="find . -name \*.md ! -path '*/vendor/*' ! -path './Documentation/*' ! -path './gopath.proto/*' ! -path './release/*' -exec grep -E --color '[Yy]ou[r]?[ '\''.,;]' {} + || true" + local find_you_cmd="find . -name \\*.md ! -path '*/vendor/*' ! -path './Documentation/*' ! -path './gopath.proto/*' ! -path './release/*' -exec grep -E --color '[Yy]ou[r]?[ '\\''.,;]' {} + || true" run eval "${find_you_cmd}" } @@ -490,7 +491,7 @@ function receiver_name_for_package { while IFS= read -r line; do gofiles+=("$line"); done < <(go_srcs_in_module "$1") recvs=$(grep 'func ([^*]' "${gofiles[@]}" | tr ':' ' ' | \ - awk ' { print $2" "$3" "$4" "$1 }' | sed "s/[a-zA-Z\.]*go//g" | sort | uniq | \ + awk ' { print $2" "$3" "$4" "$1 }' | sed "s/[a-zA-Z\\.]*go//g" | sort | uniq | \ grep -Ev "(Descriptor|Proto|_)" | awk ' { print $3" "$4 } ' | sort | uniq -c | grep -v ' 1 ' | awk ' { print $2 } ') if [ -n "${recvs}" ]; then # shellcheck disable=SC2206 @@ -566,7 +567,7 @@ function bom_pass { run cp go.mod.tmp go.mod || return 2 if [ "${code}" -ne 0 ] ; then - log_error -e "license-bill-of-materials (code: ${code}) failed with:\n${output}" + log_error -e "license-bill-of-materials (code: ${code}) failed with:\\n${output}" return 255 else echo "${output}" > "bom-now.json.tmp" @@ -598,7 +599,7 @@ function dep_pass { for dup in ${duplicates}; do log_error "FAIL: inconsistent versions for depencency: ${dup}" - echo "${all_dependencies}" | grep "${dup}" | sed "s|\([^,]*\),\([^,]*\),\([^,]*\)| - \1@\2 from: \3|g" + echo "${all_dependencies}" | grep "${dup}" | sed "s|\\([^,]*\\),\\([^,]*\\),\\([^,]*\\)| - \\1@\\2 from: \\3|g" done if [[ -n "${duplicates}" ]]; then log_error "FAIL: inconsistent dependencies" @@ -685,7 +686,7 @@ function mod_tidy_pass { function run_pass { local pass="${1}" shift 1 - log_callout -e "\n'${pass}' started at $(date)" + log_callout -e "\\n'${pass}' started at $(date)" if "${pass}_pass" "$@" ; then log_success "'${pass}' completed at $(date)" else