From 265612111fbe320efba131f25207858cbf2adcc6 Mon Sep 17 00:00:00 2001 From: Ivan Valdes Date: Wed, 11 Dec 2024 23:05:31 -0800 Subject: [PATCH] scripts: fix shellws check Originally this was intended to be a clean up. But after further investigation the original code didn't work. It didn't detect tabs in shell scripts. Signed-off-by: Ivan Valdes --- .../recipes/grpc_gateway/user_add.sh | 1 + scripts/test.sh | 19 ++++--------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/client/v3/experimental/recipes/grpc_gateway/user_add.sh b/client/v3/experimental/recipes/grpc_gateway/user_add.sh index ec538674320..3d86d03558b 100644 --- a/client/v3/experimental/recipes/grpc_gateway/user_add.sh +++ b/client/v3/experimental/recipes/grpc_gateway/user_add.sh @@ -51,6 +51,7 @@ tokengen() { } add_user() { + log_callout "Ensuring no tab-based indention in shell scripts" json=$(printf '{"name": "%s", "password": "%s"}' \ "$(escape "$1")" \ "$(escape "$2")" diff --git a/scripts/test.sh b/scripts/test.sh index 16312967eae..3908e2549ad 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -340,24 +340,13 @@ 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.sh" "./scripts/build-docker.sh" "./scripts/release.sh" ) - log_cmd "grep -E -n $'^ *${TAB}' ${files[*]}" - # shellcheck disable=SC2086 - if grep -E -n $'^ *${TAB}' "${files[@]}" | sed $'s|${TAB}|[\\\\tab]|g'; then + if files=$(find . -name '*.sh' -print0 | xargs -0 grep -E -n $'^\s*\t'); 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" - return 1 - else - log_success "SUCCESS: no tabulators found." - return 0 + log_warning "Try: sed -i 's|\\t| |g' $(echo "${files}" | cut -d: -f1 | paste -sd ' ')" + return 255 fi + log_success "SUCCESS: no tabulators found." } function markdown_marker_pass {