Skip to content

Commit 674f07e

Browse files
committed
check: Add suite shellcheck
This is based on a similar suite I drafted for zulip-mobile back in... 2019, yikes. It looks like at the time the thing that stopped me from merging it there was the question of how to handle Shellcheck as a dependency. But that needn't be a barrier to merging it -- it just needs to go into the list of "extra suites" that don't run by default. As a bonus we can give a nice error message when missing.
1 parent 3d47df4 commit 674f07e

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

tools/check

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ this_dir=${BASH_SOURCE[0]%/*}
2626

2727
default_suites=(analyze test build_runner drift icons)
2828
extra_suites=(
29+
shellcheck # Requires its own dependency, from outside the pub system.
2930
)
3031

3132
usage() {
@@ -69,7 +70,7 @@ while (( $# )); do
6970
--all-files) opt_files=all; shift;;
7071
--all) opt_files=all; opt_all=1; shift;;
7172
--fix) opt_fix=1; shift;;
72-
analyze|test|build_runner|drift|icons)
73+
analyze|test|build_runner|drift|icons|shellcheck)
7374
opt_suites+=("$1"); shift;;
7475
*) usage;;
7576
esac
@@ -256,6 +257,35 @@ run_icons() {
256257
check_no_changes "icon updates" "${outputs[@]}"
257258
}
258259

260+
run_shellcheck() {
261+
# Omitted from this check: nothing (nothing known, anyway).
262+
files_check tools/ '!*.'{dart,js,json} \
263+
|| return 0
264+
265+
# Shellcheck is fast, <1s; so if we touched any possible targets at all,
266+
# just run on the full list of targets.
267+
# shellcheck disable=SC2207 # filenames in our own tree, assume well-behaved
268+
targets=(
269+
$(git grep -l '#!.*sh\b' -- tools/)
270+
$(git ls-files -- tools/'*.sh')
271+
)
272+
273+
if ! type shellcheck >/dev/null 2>&1; then
274+
cat >&2 <<EOF
275+
shellcheck: command not found
276+
277+
Consider installing Shellcheck:
278+
https://github.com/koalaman/shellcheck#installing
279+
280+
Alternatively, skip running the \`shellcheck\` suite.
281+
See \`tools/check --help\`.
282+
EOF
283+
return 1
284+
fi
285+
286+
shellcheck -x --shell=bash -- "${targets[@]}"
287+
}
288+
259289
failed=()
260290
for suite in "${opt_suites[@]}"; do
261291
echo "Running $suite..."
@@ -265,6 +295,7 @@ for suite in "${opt_suites[@]}"; do
265295
build_runner) run_build_runner ;;
266296
drift) run_drift ;;
267297
icons) run_icons ;;
298+
shellcheck) run_shellcheck ;;
268299
*) echo >&2 "Internal error: unknown suite $suite" ;;
269300
esac || failed+=( "$suite" )
270301
done

0 commit comments

Comments
 (0)