Fail on errors while getting linter versions

This commit is contained in:
Marco Ferrari 2020-11-02 21:54:26 +01:00
parent 5a04bd9875
commit 3911130038
2 changed files with 20 additions and 16 deletions

View file

@ -281,11 +281,10 @@ for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
if ! command -v "${LINTER_NAME}" 1&>/dev/null 2>&1; then if ! command -v "${LINTER_NAME}" 1&>/dev/null 2>&1; then
# Failed # Failed
error "Failed to find [${LINTER_NAME}] in system!" fatal "Failed to find [${LINTER_NAME}] in system!"
fatal "[${VALIDATE_INSTALL_CMD}]"
else else
# Success # Success
debug "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]} in system location: ${F[W]}[${VALIDATE_INSTALL_CMD}]" debug "Successfully found binary for ${F[W]}[${LINTER_NAME}]${F[B]}."
fi fi
done done

View file

@ -55,25 +55,29 @@ BuildLinterVersions() {
#################### ####################
if [[ ${LINTER} == "arm-ttk" ]]; then if [[ ${LINTER} == "arm-ttk" ]]; then
# Need specific command for ARM # Need specific command for ARM
mapfile -t GET_VERSION_CMD < <(grep -iE 'version' "${ARM_TTK_PSD1}" | xargs 2>&1) GET_VERSION_CMD="$(grep -iE 'version' "${ARM_TTK_PSD1}" | xargs 2>&1)"
elif [[ ${LINTER} == "protolint" ]] || [[ ${LINTER} == "editorconfig-checker" ]] || [[ ${LINTER} == "bash-exec" ]]; then elif [[ ${LINTER} == "protolint" ]] || [[ ${LINTER} == "editorconfig-checker" ]] || [[ ${LINTER} == "bash-exec" ]]; then
# Need specific command for Protolint and editorconfig-checker # Need specific command for Protolint and editorconfig-checker
mapfile -t GET_VERSION_CMD < <(echo "--version not supported") GET_VERSION_CMD="$(echo "--version not supported")"
elif [[ ${LINTER} == "jsonlint" ]]; then
# Workaround for https://github.com/zaach/jsonlint/issues/122
# Delete after that issue is resolved
GET_VERSION_CMD="$("${LINTER}" --version 2>&1 || true)"
elif [[ ${LINTER} == "lintr" ]]; then elif [[ ${LINTER} == "lintr" ]]; then
# Need specific command for lintr (--slave is deprecated in R 4.0 and replaced by --no-echo) # Need specific command for lintr (--slave is deprecated in R 4.0 and replaced by --no-echo)
mapfile -t GET_VERSION_CMD < <(R --slave -e "r_ver <- R.Version()\$version.string; \ GET_VERSION_CMD="$(R --slave -e "r_ver <- R.Version()\$version.string; \
lintr_ver <- packageVersion('lintr'); \ lintr_ver <- packageVersion('lintr'); \
glue::glue('lintr { lintr_ver } on { r_ver }')") glue::glue('lintr { lintr_ver } on { r_ver }')")"
elif [[ ${LINTER} == "lua" ]]; then elif [[ ${LINTER} == "lua" ]]; then
# Semi standardversion command # Semi standardversion command
mapfile -t GET_VERSION_CMD < <("${LINTER}" -v 2>&1) GET_VERSION_CMD="$("${LINTER}" -v 2>&1)"
elif [[ ${LINTER} == "terrascan" ]]; then elif [[ ${LINTER} == "terrascan" ]]; then
mapfile -t GET_VERSION_CMD < <("${LINTER}" version 2>&1) GET_VERSION_CMD="$("${LINTER}" version 2>&1)"
elif [[ ${LINTER} == "checkstyle" ]]; then elif [[ ${LINTER} == "checkstyle" ]]; then
mapfile -t GET_VERSION_CMD < <("java -jar /usr/bin/${LINTER}" --version 2>&1) GET_VERSION_CMD="$(java -jar "/usr/bin/${LINTER}" --version 2>&1)"
else else
# Standard version command # Standard version command
mapfile -t GET_VERSION_CMD < <("${LINTER}" --version 2>&1) GET_VERSION_CMD="$("${LINTER}" --version 2>&1)"
fi fi
####################### #######################
@ -84,15 +88,16 @@ BuildLinterVersions() {
############################## ##############################
# Check the shell for errors # # Check the shell for errors #
############################## ##############################
if [ ${ERROR_CODE} -ne 0 ] || [ -z "${GET_VERSION_CMD[*]}" ]; then debug "Linter version for ${LINTER}: ${GET_VERSION_CMD}. Error code: ${ERROR_CODE}"
WriteFile "${LINTER}" "Failed to get version info" if [ ${ERROR_CODE} -ne 0 ]; then
fatal "[${LINTER}]: Failed to get version info for:" WriteFile "${LINTER}" "Failed to get version info: ${GET_VERSION_CMD}"
fatal "[${LINTER}]: Failed to get version info: ${GET_VERSION_CMD}"
else else
########################## ##########################
# Print the version info # # Print the version info #
########################## ##########################
info "Successfully found version for ${F[W]}[${LINTER}]${F[B]}: ${F[W]}${GET_VERSION_CMD[*]}" info "Successfully found version for ${F[W]}[${LINTER}]${F[B]}: ${F[W]}${GET_VERSION_CMD}"
WriteFile "${LINTER}" "${GET_VERSION_CMD[*]}" WriteFile "${LINTER}" "${GET_VERSION_CMD}"
fi fi
fi fi
done done