correcting lint.sh to properly use exit instead of return

This commit is contained in:
Georg Lauterbach 2020-12-10 10:30:39 +01:00
parent 2629b57590
commit 31f593eee9
No known key found for this signature in database
GPG Key ID: 2FDC58699AF121C6
1 changed files with 24 additions and 32 deletions

View File

@ -1,10 +1,10 @@
#! /bin/bash #! /bin/bash
# version v0.1.0 stable # version v0.1.1 stable
# executed by TravisCI / manually # executed by TravisCI / manually
# task checks files agains linting targets # task checks files agains linting targets
SCRIPT="LINT TESTS" SCRIPT="lint.sh"
function _get_current_directory function _get_current_directory
{ {
@ -24,7 +24,7 @@ _get_current_directory
# ? ERRORS # ? ERRORS
set -eEuo pipefail set -eEuo pipefail
trap '__log_err ${FUNCNAME[0]:-"?"} ${_:-"?"} ${LINENO:-"?"} ${?:-"?"}' ERR trap '__log_err ${FUNCNAME[0]:-'?'} ${_:-'?'} ${LINENO:-'?'} ${?:-'?'}' ERR
function __log_err function __log_err
{ {
@ -34,7 +34,7 @@ function __log_err
EXIT_CODE="${4}" EXIT_CODE="${4}"
printf "\n \e[1m\e[31mUNCHECKED ERROR\e[0m\n%s\n%s\n%s\n%s\n\n" \ printf "\n \e[1m\e[31mUNCHECKED ERROR\e[0m\n%s\n%s\n%s\n%s\n\n" \
" script = ${SCRIPT}" \ " script = ${SCRIPT,,}" \
" function = ${FUNC_NAME}" \ " function = ${FUNC_NAME}" \
" line = ${LINE}" \ " line = ${LINE}" \
" exit code = ${EXIT_CODE}" " exit code = ${EXIT_CODE}"
@ -52,19 +52,11 @@ function __log_info
" message = ${*}" " message = ${*}"
} }
function __log_warning function __log_failure
{
printf "\n \e[93m%s\e[0m\n%s\n%s\n\n" \
"${SCRIPT}" \
" type = WARNING" \
" message = ${*}"
}
function __log_abort
{ {
printf "\n \e[91m%s\e[0m\n%s\n%s\n\n" \ printf "\n \e[91m%s\e[0m\n%s\n%s\n\n" \
"${SCRIPT}" \ "${SCRIPT}" \
" type = ABORT" \ " type = FAILURE" \
" message = ${*:-"errors encountered"}" " message = ${*:-"errors encountered"}"
} }
@ -86,8 +78,8 @@ function _eclint
if ! __in_path "${LINT[0]}" if ! __in_path "${LINT[0]}"
then then
__log_abort 'linter not in PATH' __log_failure 'linter not in PATH'
return 102 return 2
fi fi
__log_info 'linter version:' "$(${LINT[0]} --version)" __log_info 'linter version:' "$(${LINT[0]} --version)"
@ -96,8 +88,8 @@ function _eclint
then then
__log_success 'no errors detected' __log_success 'no errors detected'
else else
__log_abort __log_failure
return 101 return 1
fi fi
} }
@ -108,8 +100,8 @@ function _hadolint
if ! __in_path "${LINT[0]}" if ! __in_path "${LINT[0]}"
then then
__log_abort 'linter not in PATH' __log_failure 'linter not in PATH'
return 102 return 2
fi fi
__log_info 'linter version:' \ __log_info 'linter version:' \
@ -120,8 +112,8 @@ function _hadolint
then then
__log_success 'no errors detected' __log_success 'no errors detected'
else else
__log_abort __log_failure
return 101 return 1
fi fi
} }
@ -133,8 +125,8 @@ function _shellcheck
if ! __in_path "${LINT[0]}" if ! __in_path "${LINT[0]}"
then then
__log_abort 'linter not in PATH' __log_failure 'linter not in PATH'
return 102 return 2
fi fi
__log_info 'linter version:' \ __log_info 'linter version:' \
@ -149,7 +141,7 @@ function _shellcheck
cd "$(realpath "$(dirname "$(readlink -f "${FILE}")")")" cd "$(realpath "$(dirname "$(readlink -f "${FILE}")")")"
if ! "${LINT[@]}" "$(basename -- "${FILE}")" if ! "${LINT[@]}" "$(basename -- "${FILE}")"
then then
return 1 exit 1
fi fi
) )
then then
@ -167,7 +159,7 @@ function _shellcheck
cd "$(realpath "$(dirname "$(readlink -f "${FILE}")")")" cd "$(realpath "$(dirname "$(readlink -f "${FILE}")")")"
if ! "${LINT[@]}" "$(basename -- "${FILE}")" if ! "${LINT[@]}" "$(basename -- "${FILE}")"
then then
return 1 exit 1
fi fi
) )
then then
@ -182,7 +174,7 @@ function _shellcheck
cd "$(realpath "$(dirname "$(readlink -f "${FILE}")")")" cd "$(realpath "$(dirname "$(readlink -f "${FILE}")")")"
if ! "${LINT[@]}" "$(basename -- "${FILE}")" if ! "${LINT[@]}" "$(basename -- "${FILE}")"
then then
return 1 exit 1
fi fi
) )
then then
@ -192,8 +184,8 @@ function _shellcheck
if [[ ${ERR} -eq 1 ]] if [[ ${ERR} -eq 1 ]]
then then
__log_abort 'errors encountered' __log_failure 'errors encountered'
return 101 return 1
else else
__log_success 'no errors detected' __log_success 'no errors detected'
fi fi
@ -206,9 +198,9 @@ function _main
'hadolint' ) _hadolint ;; 'hadolint' ) _hadolint ;;
'shellcheck' ) _shellcheck ;; 'shellcheck' ) _shellcheck ;;
*) *)
__log_abort \ __log_failure \
"lint.sh: '${1}' is not a command nor an option. See 'make help'." "${SCRIPT}: '${1}' is not a command nor an option. See 'make help'."
exit 11 exit 3
;; ;;
esac esac
} }