mirror of
https://github.com/super-linter/super-linter.git
synced 2024-10-05 18:54:37 -04:00
chore: shorten linter versions
Shorten the linter versions file by keeping only the version string for each linter, instead of the entire output of the version command
This commit is contained in:
parent
5d6e3fcecc
commit
ed1cbec915
3 changed files with 176 additions and 20 deletions
11
Makefile
11
Makefile
|
@ -342,7 +342,7 @@ lint-subset-files-enable-expensive-io-checks: ## Lint a small subset of files in
|
|||
$(SUPER_LINTER_TEST_CONTAINER_URL)
|
||||
|
||||
.PHONY: test-lib
|
||||
test-lib: test-globals-languages test-linter-rules test-build-file-list test-detect-files test-github-event test-setup-ssh test-validation test-output test-linter-commands ## Test super-linter libs and globals
|
||||
test-lib: test-globals-languages test-linter-rules test-build-file-list test-detect-files test-github-event test-setup-ssh test-validation test-output test-linter-commands test-linter-versions ## Test super-linter libs and globals
|
||||
|
||||
.PHONY: test-globals-languages
|
||||
test-globals-languages: ## Test globals/languages.sh
|
||||
|
@ -435,6 +435,15 @@ test-linter-commands: ## Test linterCommands
|
|||
--rm \
|
||||
$(SUPER_LINTER_TEST_CONTAINER_URL)
|
||||
|
||||
.PHONY: test-linter-versions
|
||||
test-linter-versions: ## Test linterVersions
|
||||
docker run \
|
||||
-v "$(CURDIR):/tmp/lint" \
|
||||
-w /tmp/lint \
|
||||
--entrypoint /tmp/lint/test/lib/linterVersionsTest.sh \
|
||||
--rm \
|
||||
$(SUPER_LINTER_TEST_CONTAINER_URL)
|
||||
|
||||
# Run this test against a small directory because we're only interested in
|
||||
# loading default configuration files. The directory that we run super-linter
|
||||
# against should not be .github because that includes default linter rules.
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/functions/log.sh # Source the function script(s)
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/functions/languages.sh
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/functions/output.sh
|
||||
|
||||
##############################
|
||||
# Linter command names array #
|
||||
##############################
|
||||
|
@ -103,20 +113,55 @@ rm -rfv "${VERSION_FILE}"
|
|||
|
||||
echo "Building linter version file ${VERSION_FILE} for the following linters: ${LINTER_NAMES_ARRAY[*]}..."
|
||||
|
||||
for LINTER in "${LINTER_NAMES_ARRAY[@]}"; do
|
||||
# Some linters need to account for special commands to get their version
|
||||
for LANGUAGE in "${!LINTER_NAMES_ARRAY[@]}"; do
|
||||
LINTER="${LINTER_NAMES_ARRAY[${LANGUAGE}]}"
|
||||
echo "Get version for ${LINTER}"
|
||||
|
||||
if [[ ${LINTER} == "arm-ttk" ]]; then
|
||||
GET_VERSION_CMD="$(grep -iE 'version' "/usr/bin/arm-ttk" | xargs 2>&1)"
|
||||
# Some linters don't support a "get version" command
|
||||
elif [[ ${LINTER} == "bash-exec" ]] || [[ ${LINTER} == "gherkin-lint" ]]; then
|
||||
GET_VERSION_CMD="Version command not supported"
|
||||
# Some linters need to account for special commands to get their version instead
|
||||
# of the default --version option
|
||||
|
||||
if [[ "${LINTER}" == "actionlint" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | head -n 1)"
|
||||
elif [[ "${LINTER}" == "ansible-lint" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | grep -v 'available' | awk '{ print $2 }')"
|
||||
elif [[ ${LINTER} == "arm-ttk" ]]; then
|
||||
GET_VERSION_CMD="$(grep -iE 'version' "/usr/bin/arm-ttk" | xargs 2>&1 | awk '{ print $3 }')"
|
||||
elif [[ "${LINTER}" == "black" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | grep 'black' | awk '{ print $2 }')"
|
||||
elif [[ "${LINTER}" == "cfn-lint" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $2 }')"
|
||||
elif [[ "${LINTER}" == "chktex" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version 2>/dev/null | grep 'ChkTeX' | awk '{ print $2 }')"
|
||||
elif [[ ${LINTER} == "checkstyle" ]] || [[ ${LINTER} == "google-java-format" ]]; then
|
||||
GET_VERSION_CMD="$(java -jar "/usr/bin/${LINTER}" --version 2>&1)"
|
||||
GET_VERSION_CMD="$(java -jar "/usr/bin/${LINTER}" --version 2>&1 | awk '{ print $3 }')"
|
||||
elif [[ "${LINTER}" == "clang-format" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $3 }')"
|
||||
elif [[ "${LINTER}" == "clj-kondo" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $2 }')"
|
||||
elif [[ ${LINTER} == "clippy" ]]; then
|
||||
GET_VERSION_CMD="$(cargo clippy --version 2>&1)"
|
||||
GET_VERSION_CMD="$(cargo clippy --version 2>&1 | awk '{ print $2 }')"
|
||||
elif [[ "${LINTER}" == "cpplint" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | grep 'cpplint' | grep -v 'github' | awk '{ print $2 }')"
|
||||
elif [[ "${LINTER}" == "dart" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $4 }')"
|
||||
elif [[ "${LINTER}" == "dotenv-linter" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $2 }')"
|
||||
elif [[ ${LINTER} == "editorconfig-checker" ]]; then
|
||||
GET_VERSION_CMD="$(${LINTER} -version)"
|
||||
elif [[ "${LINTER}" == "flake8" ]]; then
|
||||
GET_VERSION_CMD="$(${LINTER} --version | grep 'mccabe' | awk '{ print $1 }')"
|
||||
elif [[ ${LINTER} == "gitleaks" ]]; then
|
||||
GET_VERSION_CMD="$(${LINTER} version)"
|
||||
elif [[ "${LINTER}" == "golangci-lint" ]]; then
|
||||
GET_VERSION_CMD="$(${LINTER} --version | awk '{ print $4 }')"
|
||||
elif [[ "${LINTER}" == "goreleaser" ]]; then
|
||||
GET_VERSION_CMD="$(${LINTER} --version | grep 'GitVersion' | awk '{ print $2 }')"
|
||||
elif [[ "${LINTER}" == "hadolint" ]]; then
|
||||
GET_VERSION_CMD="$(${LINTER} --version | awk '{ print $4 }')"
|
||||
elif [[ "${LINTER}" == "isort" ]]; then
|
||||
GET_VERSION_CMD="$(${LINTER} --version | grep 'VERSION' | awk '{ print $2 }')"
|
||||
elif [[ "${LINTER}" == "ktlint" ]]; then
|
||||
GET_VERSION_CMD="$(${LINTER} --version | awk '{ print $3 }')"
|
||||
elif [[ ${LINTER} == "kubeconform" ]]; then
|
||||
GET_VERSION_CMD="$(${LINTER} -v)"
|
||||
elif [[ ${LINTER} == "lintr" ]]; then
|
||||
|
@ -124,34 +169,95 @@ for LINTER in "${LINTER_NAMES_ARRAY[@]}"; do
|
|||
GET_VERSION_CMD="$(R --slave -e "r_ver <- R.Version()\$version.string; \
|
||||
lintr_ver <- packageVersion('lintr'); \
|
||||
glue::glue('lintr { lintr_ver } on { r_ver }')")"
|
||||
elif [[ ${LINTER} == "protolint" ]] || [[ ${LINTER} == "gitleaks" ]]; then
|
||||
GET_VERSION_CMD="$(${LINTER} version)"
|
||||
elif [[ "${LINTER}" == "perl" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | grep 'This' | awk '{ print $9 }')"
|
||||
elif [[ "${LINTER}" == "php" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | grep 'cli' | awk '{ print $2 }')"
|
||||
elif [[ "${LINTER}" == "phpcs" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $3 }')"
|
||||
elif [[ "${LINTER}" == "phpstan" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $7 }')"
|
||||
elif [[ ${LINTER} == "protolint" ]]; then
|
||||
GET_VERSION_CMD="$(${LINTER} version | awk '{ print $3 }')"
|
||||
elif [[ ${LINTER} == "psalm" ]]; then
|
||||
GET_VERSION_CMD="$(${LINTER} --version | awk '{ print $2 }')"
|
||||
elif [[ "${LINTER}" == "pyink" ]]; then
|
||||
GET_VERSION_CMD="$(${LINTER} --version | grep 'pyink' | awk '{ print $2 }')"
|
||||
elif [[ ${LINTER} == "pylint" ]]; then
|
||||
GET_VERSION_CMD="$(${LINTER} --version | grep 'pylint' | awk '{ print $2 }')"
|
||||
elif [[ ${LINTER} == "lua" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" -v 2>&1)"
|
||||
GET_VERSION_CMD="$("${LINTER}" -v 2>&1 | awk '{ print $2 }')"
|
||||
elif [[ ${LINTER} == "mypy" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $2 }')"
|
||||
elif [[ "${LINTER}" == "npm-groovy-lint" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | grep 'npm-groovy-lint' | awk '{ print $3 }')"
|
||||
elif [[ "${LINTER}" == "pwsh" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $2 }')"
|
||||
elif [[ "${LINTER}" == "R" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | head -n 1 | awk '{ print $3 }')"
|
||||
elif [[ "${LINTER}" == "raku" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | grep 'Rakudo' | awk '{ print $4 }' | sed 's/\.$//')"
|
||||
elif [[ ${LINTER} == "renovate-config-validator" ]]; then
|
||||
GET_VERSION_CMD="$(renovate --version 2>&1)"
|
||||
GET_VERSION_CMD="$(renovate --version 2>/dev/null)"
|
||||
elif [[ "${LINTER}" == "ruff" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $2 }')"
|
||||
elif [[ "${LINTER}" == "rustfmt" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $2 }')"
|
||||
elif [[ "${LINTER}" == "scalafmt" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $2 }')"
|
||||
elif [[ "${LINTER}" == "shellcheck" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | grep 'version:' | awk '{ print $2 }')"
|
||||
elif [[ "${LINTER}" == "snakefmt" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $3 }')"
|
||||
elif [[ "${LINTER}" == "sqlfluff" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $3 }')"
|
||||
elif [[ ${LINTER} == "terraform" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | head -n 1 | awk '{ print $2 }')"
|
||||
elif [[ "${LINTER}" == "terragrunt" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $2 }')"
|
||||
elif [[ ${LINTER} == "terrascan" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" version 2>&1)"
|
||||
else
|
||||
GET_VERSION_CMD="$("${LINTER}" version 2>&1 | awk '{ print $2 }')"
|
||||
elif [[ ${LINTER} == "tflint" ]]; then
|
||||
# Unset TF_LOG_LEVEL so that the version file doesn't contain debug log when running
|
||||
# commands that read TF_LOG_LEVEL or TFLINT_LOG, which are likely set to DEBUG when
|
||||
# building the versions file
|
||||
GET_VERSION_CMD="$(
|
||||
unset TF_LOG_LEVEL
|
||||
unset TFLINT_LOG
|
||||
"${LINTER}" --version 2>&1
|
||||
"${LINTER}" --version | grep 'version' | awk '{ print $3 }'
|
||||
)"
|
||||
elif [[ ${LINTER} == "xmllint" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version 2>&1 | grep 'xmllint' | awk '{ print $5 }')"
|
||||
elif [[ "${LINTER}" == "yamllint" ]]; then
|
||||
GET_VERSION_CMD="$("${LINTER}" --version | awk '{ print $2 }')"
|
||||
# Some linters don't support a "get version" command
|
||||
elif [[ ${LINTER} == "bash-exec" ]] || [[ ${LINTER} == "gherkin-lint" ]]; then
|
||||
GET_VERSION_CMD="Version command not supported"
|
||||
else
|
||||
GET_VERSION_CMD="$("${LINTER}" --version 2>&1)"
|
||||
fi
|
||||
|
||||
ERROR_CODE=$?
|
||||
if [ ${ERROR_CODE} -ne 0 ]; then
|
||||
echo "[ERROR]: Failed to get version info for ${LINTER}. Exit code: ${ERROR_CODE}. Output: ${GET_VERSION_CMD}"
|
||||
echo "[ERROR]: Failed to get version echo for ${LINTER}. Exit code: ${ERROR_CODE}. Output: ${GET_VERSION_CMD}"
|
||||
exit 1
|
||||
else
|
||||
echo "Successfully found version for ${LINTER}: ${GET_VERSION_CMD}"
|
||||
if ! echo "${LINTER}: ${GET_VERSION_CMD}" >>"${VERSION_FILE}" 2>&1; then
|
||||
echo "[ERROR] Failed to write data to file!"
|
||||
if ! echo "[${LANGUAGE}] ${LINTER}: ${GET_VERSION_CMD}" >>"${VERSION_FILE}" 2>&1; then
|
||||
echo "[ERROR]: Failed to write data to file!"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if ! RemoveAnsiColorCodesFromFile "${VERSION_FILE}"; then
|
||||
echo "[ERROR]: Failed to write remove ANSI color codes from file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! sort --ignore-case --unique --output="${VERSION_FILE}" "${VERSION_FILE}"; then
|
||||
echo "[ERROR]:Failed to sort file!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo -e "Versions file contents:\n$(cat "${VERSION_FILE}")"
|
||||
|
|
41
test/lib/linterVersionsTest.sh
Executable file
41
test/lib/linterVersionsTest.sh
Executable file
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source "test/testUtils.sh"
|
||||
|
||||
VersionsFileSortTest() {
|
||||
local FUNCTION_NAME
|
||||
FUNCTION_NAME="${FUNCNAME[0]}"
|
||||
info "${FUNCTION_NAME} start"
|
||||
|
||||
if sort --check "${VERSION_FILE}"; then
|
||||
fatal "Linters version file (${LINTERS_VERSION_FILE_LINES_COUNT}) is not sorted"
|
||||
fi
|
||||
|
||||
notice "${FUNCTION_NAME} PASS"
|
||||
}
|
||||
|
||||
VersionsFileLengthTest() {
|
||||
local FUNCTION_NAME
|
||||
FUNCTION_NAME="${FUNCNAME[0]}"
|
||||
info "${FUNCTION_NAME} start"
|
||||
|
||||
local LINTERS_VERSION_FILE_LINES_COUNT
|
||||
LINTERS_VERSION_FILE_LINES_COUNT=$(wc --lines "${VERSION_FILE}" | awk '{print $1}')
|
||||
debug "Linters version file lines count: ${LINTERS_VERSION_FILE_LINES_COUNT}"
|
||||
|
||||
if [[ ${LINTERS_VERSION_FILE_LINES_COUNT} -ne ${#LANGUAGE_ARRAY[@]} ]]; then
|
||||
fatal "Linters version file lines count (${LINTERS_VERSION_FILE_LINES_COUNT}) doesn't match the length of the languages array (${#LANGUAGE_ARRAY[@]}). Is a version descriptor missing from the versions file, or does a version string span more than one line?"
|
||||
fi
|
||||
|
||||
fatal "Not yet implemented"
|
||||
|
||||
notice "${FUNCTION_NAME} PASS"
|
||||
}
|
||||
|
||||
VersionsFileSortTest
|
||||
VersionsFileLengthTest
|
Loading…
Reference in a new issue