2020-09-03 10:12:49 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2020-11-12 12:27:34 -05:00
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
########### Super-Linter linting Functions @admiralawkbar ######################
|
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
#### Function GetLinterVersions ################################################
|
|
|
|
GetLinterVersions() {
|
|
|
|
#########################
|
|
|
|
# Print version headers #
|
|
|
|
#########################
|
|
|
|
debug "---------------------------------------------"
|
2021-12-10 11:15:12 -05:00
|
|
|
debug "WRITE_LINTER_VERSIONS_FILE: ${WRITE_LINTER_VERSIONS_FILE}"
|
|
|
|
debug "VERSION_FILE: ${VERSION_FILE}"
|
2020-11-12 12:27:34 -05:00
|
|
|
debug "Linter Version Info:"
|
|
|
|
|
2021-12-10 11:15:12 -05:00
|
|
|
if [ "${WRITE_LINTER_VERSIONS_FILE}" = "true" ]; then
|
2020-11-12 12:27:34 -05:00
|
|
|
debug "Building linter version file..."
|
|
|
|
if BuildLinterVersions "${VERSION_FILE}" "${LINTER_NAMES_ARRAY[@]}"; then
|
|
|
|
info "Linter version file built correctly."
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
fatal "Error while building the versions file."
|
|
|
|
fi
|
2021-12-10 11:15:12 -05:00
|
|
|
else
|
|
|
|
debug "Skipping versions file build..."
|
2020-11-12 12:27:34 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
################################
|
|
|
|
# Cat the linter versions file #
|
|
|
|
################################
|
|
|
|
CAT_CMD=$(cat "${VERSION_FILE}" 2>&1)
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ ${ERROR_CODE} -ne 0 ]; then
|
|
|
|
# Failure
|
|
|
|
fatal "Failed to view version file:[${VERSION_FILE}]"
|
|
|
|
else
|
|
|
|
# Success
|
|
|
|
debug "${CAT_CMD}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
#########################
|
|
|
|
# Print version footers #
|
|
|
|
#########################
|
|
|
|
debug "---------------------------------------------"
|
|
|
|
}
|
|
|
|
################################################################################
|
|
|
|
#### Function BuildLinterVersions ##############################################
|
2020-09-03 10:56:34 -04:00
|
|
|
BuildLinterVersions() {
|
2020-11-02 16:39:34 -05:00
|
|
|
VERSION_FILE="${1}" && shift
|
|
|
|
LINTER_ARRAY=("$@")
|
|
|
|
|
2020-11-02 16:51:07 -05:00
|
|
|
debug "Building linter version file ${VERSION_FILE} for the following linters: ${LINTER_ARRAY[*]}..."
|
2020-09-03 10:12:49 -04:00
|
|
|
|
|
|
|
##########################################################
|
|
|
|
# Go through the array of linters and print version info #
|
|
|
|
##########################################################
|
|
|
|
for LINTER in "${LINTER_ARRAY[@]}"; do
|
|
|
|
if [ -n "${LINTER}" ]; then
|
|
|
|
####################
|
|
|
|
# Get the versions #
|
|
|
|
####################
|
|
|
|
if [[ ${LINTER} == "arm-ttk" ]]; then
|
|
|
|
# Need specific command for ARM
|
2020-11-02 16:39:34 -05:00
|
|
|
GET_VERSION_CMD="$(grep -iE 'version' "/usr/bin/arm-ttk" | xargs 2>&1)"
|
2022-01-04 11:07:45 -05:00
|
|
|
elif [[ ${LINTER} == "bash-exec" ]] || [[ ${LINTER} == "gherkin-lint" ]] || [[ ${LINTER} == "gitleaks" ]] || [[ ${LINTER} == "find_unicode_control2.py" ]]; then
|
2020-09-03 10:12:49 -04:00
|
|
|
# Need specific command for Protolint and editorconfig-checker
|
2020-11-02 15:54:26 -05:00
|
|
|
GET_VERSION_CMD="$(echo "--version not supported")"
|
2020-09-03 10:12:49 -04:00
|
|
|
elif [[ ${LINTER} == "lintr" ]]; then
|
|
|
|
# Need specific command for lintr (--slave is deprecated in R 4.0 and replaced by --no-echo)
|
2020-11-02 15:54:26 -05:00
|
|
|
GET_VERSION_CMD="$(R --slave -e "r_ver <- R.Version()\$version.string; \
|
2020-09-03 10:12:49 -04:00
|
|
|
lintr_ver <- packageVersion('lintr'); \
|
2020-11-02 15:54:26 -05:00
|
|
|
glue::glue('lintr { lintr_ver } on { r_ver }')")"
|
2020-09-03 10:12:49 -04:00
|
|
|
elif [[ ${LINTER} == "lua" ]]; then
|
|
|
|
# Semi standardversion command
|
2020-11-02 15:54:26 -05:00
|
|
|
GET_VERSION_CMD="$("${LINTER}" -v 2>&1)"
|
2020-09-03 10:12:49 -04:00
|
|
|
elif [[ ${LINTER} == "terrascan" ]]; then
|
2020-11-02 15:54:26 -05:00
|
|
|
GET_VERSION_CMD="$("${LINTER}" version 2>&1)"
|
2021-09-28 18:09:21 -04:00
|
|
|
elif [[ ${LINTER} == "checkstyle" ]] || [[ ${LINTER} == "google-java-format" ]]; then
|
2020-11-02 15:54:26 -05:00
|
|
|
GET_VERSION_CMD="$(java -jar "/usr/bin/${LINTER}" --version 2>&1)"
|
2021-03-08 15:13:04 -05:00
|
|
|
elif [[ ${LINTER} == "clippy" ]]; then
|
|
|
|
GET_VERSION_CMD="$(cargo-clippy --version 2>&1)"
|
2021-04-30 12:29:15 -04:00
|
|
|
elif [[ ${LINTER} == "protolint" ]]; then
|
|
|
|
GET_VERSION_CMD="$(${LINTER} version)"
|
|
|
|
elif [[ ${LINTER} == "editorconfig-checker" ]]; then
|
|
|
|
GET_VERSION_CMD="$(${LINTER} -version)"
|
2020-09-03 10:12:49 -04:00
|
|
|
else
|
|
|
|
# Standard version command
|
2020-11-02 15:54:26 -05:00
|
|
|
GET_VERSION_CMD="$("${LINTER}" --version 2>&1)"
|
2020-09-03 10:12:49 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
2020-11-02 15:54:26 -05:00
|
|
|
debug "Linter version for ${LINTER}: ${GET_VERSION_CMD}. Error code: ${ERROR_CODE}"
|
|
|
|
if [ ${ERROR_CODE} -ne 0 ]; then
|
|
|
|
fatal "[${LINTER}]: Failed to get version info: ${GET_VERSION_CMD}"
|
2020-09-03 10:12:49 -04:00
|
|
|
else
|
|
|
|
##########################
|
|
|
|
# Print the version info #
|
|
|
|
##########################
|
2020-11-02 15:54:26 -05:00
|
|
|
info "Successfully found version for ${F[W]}[${LINTER}]${F[B]}: ${F[W]}${GET_VERSION_CMD}"
|
2020-11-02 16:39:34 -05:00
|
|
|
WriteFile "${LINTER}" "${GET_VERSION_CMD}" "${VERSION_FILE}"
|
2020-09-03 10:12:49 -04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
2020-11-12 12:27:34 -05:00
|
|
|
################################################################################
|
|
|
|
#### Function WriteFile ########################################################
|
2020-09-03 10:12:49 -04:00
|
|
|
WriteFile() {
|
|
|
|
##############
|
|
|
|
# Read Input #
|
|
|
|
##############
|
2020-11-02 16:39:34 -05:00
|
|
|
LINTER="$1" # Name of the linter
|
|
|
|
VERSION="$2" # Version returned from check
|
|
|
|
VERSION_FILE=$3 # Version file path
|
2020-09-03 10:12:49 -04:00
|
|
|
|
|
|
|
#################################
|
|
|
|
# Write the data to output file #
|
|
|
|
#################################
|
2020-11-06 17:10:09 -05:00
|
|
|
echo "${LINTER}: ${VERSION}" >>"${VERSION_FILE}" 2>&1
|
2020-09-03 10:12:49 -04:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
|
|
|
if [ $ERROR_CODE -ne 0 ]; then
|
2020-09-03 10:34:39 -04:00
|
|
|
fatal "Failed to write data to file!"
|
2020-09-03 10:12:49 -04:00
|
|
|
fi
|
|
|
|
}
|