Files
evm/scripts/shellcheck.sh
T
zeekay 5972e1b1a4 Fix shellcheck warnings in shell scripts
- Fix SC2125: Quote GOPRIVATE/GONOSUMDB values in ci_setup.sh
- Fix SC1091: Add source=/dev/null for dynamically sourced lib_luxd_clone.sh
- Fix unbound variable errors in shellcheck.sh for arrays and args
- Add -x flag to shellcheck for following sourced files
2025-12-04 14:04:20 -08:00

60 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
VERSION="v0.9.0"
# Scripts that are sourced from upstream and not maintained in this repo will not be shellchecked.
# Also ignore the local luxd clone.
IGNORED_FILES="
cmd/evm/transition-test.sh
metrics/validate.sh
luxd/*
"
function get_version {
local target_path=$1
if command -v "${target_path}" > /dev/null; then
echo "v$("${target_path}" --version | grep version: | awk '{print $2}')"
fi
}
REPO_ROOT=$( cd "$( dirname "${BASH_SOURCE[0]}" )"; cd .. && pwd )
SYSTEM_VERSION="$(get_version shellcheck)"
if [[ "${SYSTEM_VERSION}" == "${VERSION}" ]]; then
SHELLCHECK=shellcheck
else
# Try to install a local version
SHELLCHECK="${REPO_ROOT}/bin/shellcheck"
LOCAL_VERSION="$(get_version "${SHELLCHECK}")"
if [[ -z "${LOCAL_VERSION}" || "${LOCAL_VERSION}" != "${VERSION}" ]]; then
if which sw_vers &> /dev/null; then
echo "on macos, only x86_64 binaries are available so rosetta is required"
echo "to avoid using rosetta, install via homebrew: brew install shellcheck"
DIST=darwin.x86_64
else
# Linux - binaries for common arches *should* be available
arch="$(uname -i)"
DIST="linux.${arch}"
fi
curl -s -L "https://github.com/koalaman/shellcheck/releases/download/${VERSION}/shellcheck-${VERSION}.${DIST}.tar.xz" | tar Jxv -C /tmp > /dev/null
mkdir -p "$(dirname "${SHELLCHECK}")"
cp /tmp/shellcheck-"${VERSION}"/shellcheck "${SHELLCHECK}"
fi
fi
IGNORED_CONDITIONS=()
for file in ${IGNORED_FILES}; do
if [[ ${#IGNORED_CONDITIONS[@]} -gt 0 ]]; then
IGNORED_CONDITIONS+=(-o)
fi
IGNORED_CONDITIONS+=(-path "${REPO_ROOT}/${file}" -prune)
done
if [[ ${#IGNORED_CONDITIONS[@]} -gt 0 ]]; then
find "${REPO_ROOT}" \( "${IGNORED_CONDITIONS[@]}" \) -o -type f -name "*.sh" -print0 | xargs -0 "${SHELLCHECK}" -x "${@:+$@}"
else
find "${REPO_ROOT}" -type f -name "*.sh" -print0 | xargs -0 "${SHELLCHECK}" -x "${@:+$@}"
fi