From ea18e96bc02cc9516f5fe2bd354d386971ebda87 Mon Sep 17 00:00:00 2001 From: James Hegedus Date: Fri, 23 Dec 2022 20:40:11 +1100 Subject: [PATCH] ci: explicitly set shell in lint & format scripts (#1391) --- lib/functions/plugins.bash | 2 ++ scripts/format.bash | 27 +++++++++++++++++++++++++++ scripts/shellcheck.bash | 18 ++++++++++++++++-- scripts/shfmt.bash | 24 +++++++++++++++++++++++- 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100755 scripts/format.bash diff --git a/lib/functions/plugins.bash b/lib/functions/plugins.bash index f2f3b8e4..ee2e2161 100644 --- a/lib/functions/plugins.bash +++ b/lib/functions/plugins.bash @@ -94,6 +94,7 @@ plugin_add_command() { if [ -f "${plugin_path}/bin/post-plugin-add" ]; then ( export ASDF_PLUGIN_SOURCE_URL=$source_url + # shellcheck disable=SC2030 export ASDF_PLUGIN_PATH=$plugin_path "${plugin_path}/bin/post-plugin-add" ) @@ -153,6 +154,7 @@ update_plugin() { if [ -f "${plugin_path}/bin/post-plugin-update" ]; then ( + # shellcheck disable=SC2031 export ASDF_PLUGIN_PATH=$plugin_path export ASDF_PLUGIN_PREV_REF=$prev_ref export ASDF_PLUGIN_POST_REF=$post_ref diff --git a/scripts/format.bash b/scripts/format.bash new file mode 100755 index 00000000..5be8205a --- /dev/null +++ b/scripts/format.bash @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# check .sh files +# TODO(jthegedus): unlock this check later +# TODO shfmt --language-dialect posix --indent 2 --write \ +# TODO asdf.sh \ +# TODO lib/*.sh + +# check .bash files +shfmt --language-dialect bash --indent 2 --write \ + completions/*.bash \ + bin/asdf \ + bin/private/asdf-exec \ + lib/utils.bash \ + lib/commands/*.bash \ + lib/functions/*.bash \ + scripts/*.bash \ + test/test_helpers.bash \ + test/fixtures/dummy_broken_plugin/bin/* \ + test/fixtures/dummy_legacy_plugin/bin/* \ + test/fixtures/dummy_plugin/bin/* + +# check .bats files +shfmt --language-dialect bats --indent 2 --write \ + test/*.bats diff --git a/scripts/shellcheck.bash b/scripts/shellcheck.bash index 5249e8e4..2318e976 100755 --- a/scripts/shellcheck.bash +++ b/scripts/shellcheck.bash @@ -2,13 +2,27 @@ set -euo pipefail -exec shellcheck -s bash -x \ - asdf.sh \ +# check .sh files +# TODO(jthegedus): unlock this check later +# TODO shellcheck --shell sh --external-sources \ +# TODO asdf.sh \ +# TODO lib/*.sh + +# check .bash files +shellcheck --shell bash --external-sources \ completions/*.bash \ bin/asdf \ bin/private/asdf-exec \ lib/utils.bash \ lib/commands/*.bash \ + lib/functions/*.bash \ scripts/*.bash \ test/test_helpers.bash \ + test/fixtures/dummy_broken_plugin/bin/* \ + test/fixtures/dummy_legacy_plugin/bin/* \ test/fixtures/dummy_plugin/bin/* + +# check .bats files +# TODO(jthegedus): unlock this check later +# TODO shellcheck --shell bats --external-sources \ +# TODO test/*.bats diff --git a/scripts/shfmt.bash b/scripts/shfmt.bash index 461d7a53..7f256b86 100755 --- a/scripts/shfmt.bash +++ b/scripts/shfmt.bash @@ -2,4 +2,26 @@ set -euo pipefail -exec shfmt -d . +# check .sh files +# TODO(jthegedus): unlock this check later +# TODO shfmt --language-dialect posix --indent 2 --diff \ +# TODO asdf.sh \ +# TODO lib/*.sh + +# check .bash files +shfmt --language-dialect bash --indent 2 --diff \ + completions/*.bash \ + bin/asdf \ + bin/private/asdf-exec \ + lib/utils.bash \ + lib/commands/*.bash \ + lib/functions/*.bash \ + scripts/*.bash \ + test/test_helpers.bash \ + test/fixtures/dummy_broken_plugin/bin/* \ + test/fixtures/dummy_legacy_plugin/bin/* \ + test/fixtures/dummy_plugin/bin/* + +# check .bats files +shfmt --language-dialect bats --indent 2 --diff \ + test/*.bats