#!/usr/bin/env bash # Run shellcheck over every script in the repo. (Wording matters: starting the # line with "shellcheck" makes shellcheck 0.11+ parse it as a directive.) # # ./tests/shell/lint.sh # # Worth having as a gate rather than a habit: the container scripts run # unattended in a task nobody is watching, where an unquoted expansion is a # silently mis-fetched asset rather than a visible error. set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" cd "$ROOT" command -v shellcheck >/dev/null || { echo "SKIP: shellcheck not installed (apt install shellcheck)" >&2 exit 0 } # find rather than git ls-files: the Docker build context has no .git. mapfile -t scripts < <(find . -name "*.sh" -not -path "./.git/*" | sort) echo "shellcheck: ${#scripts[@]} script(s)" # -x follows `source`d files, which is the only way lib/common.sh's definitions # are visible to the scripts that use them. shellcheck -x -S warning "${scripts[@]}" echo "clean"