From c035df5317c8f116d1f9c7ffbbd5664591c7e096 Mon Sep 17 00:00:00 2001 From: Piotr Tabor Date: Mon, 26 Oct 2020 10:15:57 +0100 Subject: [PATCH] test: Detect indention done using tab (\t) in *.sh --- scripts/fix.sh | 8 ++++++++ test | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/scripts/fix.sh b/scripts/fix.sh index 0d3656df0..6bfae8809 100755 --- a/scripts/fix.sh +++ b/scripts/fix.sh @@ -10,10 +10,18 @@ function mod_tidy_fix { run go mod tidy || return 2 } +function bash_ws_fix { + log_callout "Fixing whitespaces in the bash scripts" + # Makes sure all bash scripts do use ' ' (double space) for indention. + log_cmd "% find ./ -name '*.sh' | xargs sed --follow-symlinks -i 's|\t| |g'" + find ./ -print0 -name '*.sh' | xargs -0 sed --follow-symlinks -i 's|\t| |g' +} + 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 :)" diff --git a/test b/test index 57ce53724..976a4fd59 100755 --- a/test +++ b/test @@ -306,6 +306,8 @@ function fmt_pass { commit_title \ mod_tidy \ dep \ + shellcheck \ + shellws \ ; do run_pass "${p}" "${@}" done @@ -317,6 +319,21 @@ function shellcheck_pass { fi } +function shellws_pass { + log_callout "Ensuring no tab-based indention in shell scripts" + local files + files=$(find ./ -name '*.sh' -print0 | xargs -0 ) + log_cmd "grep -E -n $'^ *\t' ${files}" + # shellcheck disable=SC2086 + if grep -E -n $'^ *\t' ${files} | sed -s $'s|\t|[\\\\tab]|g'; then + log_error "FAIL: found tab-based indention in bash scripts. Use ' ' (double space)." + return 1 + else + log_success "SUCCESS: no tabulators found." + return 0 + fi +} + function markdown_you_find_eschew_you { find . -name \*.md ! -path '*/vendor/*' ! -path './Documentation/*' ! -path './gopath.proto/*' -exec grep -E --color "[Yy]ou[r]?[ '.,;]" {} + || true }