Skip to content

Commit

Permalink
fix: lint errors from scripts/checkstyle.py (#1385)
Browse files Browse the repository at this point in the history
Co-authored-by: James Hegedus <jthegedus@hey.com>
  • Loading branch information
hyperupcall and jthegedus committed Dec 23, 2022
1 parent ea18e96 commit 3492043
Show file tree
Hide file tree
Showing 22 changed files with 254 additions and 124 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.py]
indent_size = 4
12 changes: 12 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ jobs:

- name: Run shfmt
run: scripts/shfmt.bash

checkstyle-py:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install asdf dependencies
uses: asdf-vm/actions/install@v1

- name: Run checkstyle.py
run: scripts/checkstyle.py
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bats 1.7.0
shellcheck 0.8.0
shfmt 3.5.1
python 3.10.9
6 changes: 3 additions & 3 deletions lib/commands/command-current.bash
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ plugin_current_command() {

# shellcheck disable=SC2059
current_command() {
local terminal_format="%-15s %-15s %-10s\\n"
local terminal_format="%-15s %-15s %-10s\n"
local exit_status=0
local plugin

Expand Down Expand Up @@ -75,8 +75,8 @@ check_for_deprecated_plugin() {
local new_script="${plugin_path}/bin/list-legacy-filenames"

if [ "$legacy_config" = "yes" ] && [ -f "$deprecated_script" ] && [ ! -f "$new_script" ]; then
printf "Heads up! It looks like your %s plugin is out of date. You can update it with:\\n\\n" "$plugin_name"
printf " asdf plugin-update %s\\n\\n" "$plugin_name"
printf "Heads up! It looks like your %s plugin is out of date. You can update it with:\n\n" "$plugin_name"
printf " asdf plugin-update %s\n\n" "$plugin_name"
fi
}

Expand Down
2 changes: 1 addition & 1 deletion lib/commands/command-env.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ shim_env_command() {
local env_args=("${@:3}")

if [ -z "$shim_name" ]; then
printf "usage: asdf env <command>\\n"
printf "usage: asdf env <command>\n"
exit 1
fi

Expand Down
4 changes: 2 additions & 2 deletions lib/commands/command-exec.bash
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ shim_exec_command() {
local shim_args=("${@:2}")

if [ -z "$shim_name" ]; then
printf "usage: asdf exec <command>\\n"
printf "usage: asdf exec <command>\n"
exit 1
fi

Expand All @@ -16,7 +16,7 @@ shim_exec_command() {
local executable_path="$3"

if [ ! -x "$executable_path" ]; then
printf "No %s executable found for %s %s\\n" "$shim_name" "$plugin_name" "$version" >&2
printf "No %s executable found for %s %s\n" "$shim_name" "$plugin_name" "$version" >&2
exit 2
fi

Expand Down
14 changes: 7 additions & 7 deletions lib/commands/command-export-shell-version.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ shell_command() {
shift

if [ "$#" -lt "2" ]; then
printf "Usage: asdf shell <name> {<version>|--unset}\\n" >&2
printf "false\\n"
printf "Usage: asdf shell <name> {<version>|--unset}\n" >&2
printf "false\n"
exit 1
fi

Expand All @@ -23,7 +23,7 @@ shell_command() {
if [ "$version" = "--unset" ]; then
case "$asdf_shell" in
fish)
printf "set -e %s\\n" "$version_env_var"
printf "set -e %s\n" "$version_env_var"
;;
elvish)
# Elvish doesn't have a `source` command, and eval is banned, so the
Expand All @@ -32,7 +32,7 @@ shell_command() {
printf "unset-env\n%s" "$version_env_var"
;;
*)
printf "unset %s\\n" "$version_env_var"
printf "unset %s\n" "$version_env_var"
;;
esac
exit 0
Expand All @@ -42,13 +42,13 @@ shell_command() {
fi
if ! (check_if_version_exists "$plugin" "$version"); then
version_not_installed_text "$plugin" "$version" 1>&2
printf "false\\n"
printf "false\n"
exit 1
fi

case "$asdf_shell" in
fish)
printf "set -gx %s \"%s\"\\n" "$version_env_var" "$version"
printf "set -gx %s \"%s\"\n" "$version_env_var" "$version"
;;
elvish)
# Elvish doesn't have a `source` command, and eval is banned, so the
Expand All @@ -57,7 +57,7 @@ shell_command() {
printf "set-env\n%s\n%s" "$version_env_var" "$version"
;;
*)
printf "export %s=\"%s\"\\n" "$version_env_var" "$version"
printf "export %s=\"%s\"\n" "$version_env_var" "$version"
;;
esac
}
Expand Down
8 changes: 4 additions & 4 deletions lib/commands/command-help.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
. "$(dirname "$(dirname "$0")")/lib/functions/versions.bash"

asdf_help() {
printf "version: %s\\n\\n" "$(asdf_version)"
printf "version: %s\n\n" "$(asdf_version)"
cat "$(asdf_dir)/help.txt"
}

Expand All @@ -23,7 +23,7 @@ asdf_extension_cmds() {
ext_cmd_path="$plugin_path/lib/commands"
ext_cmds="$(find "$ext_cmd_path" -name "command*.bash" 2>/dev/null)"
if [[ -n $ext_cmds ]]; then
printf "\\nPLUGIN %s\\n" "$plugin"
printf "\nPLUGIN %s\n" "$plugin"
for ext_cmd in $ext_cmds; do
ext_cmd_name="$(basename "$ext_cmd")"
sed "s/-/ /g;s/.bash//;s/command-*/ asdf $plugin/;" <<<"$ext_cmd_name"
Expand Down Expand Up @@ -78,11 +78,11 @@ help_command() {
(print_plugin_help "$plugin_path")
fi
else
printf "No documentation for plugin %s\\n" "$plugin_name" >&2
printf "No documentation for plugin %s\n" "$plugin_name" >&2
exit 1
fi
else
printf "No plugin named %s\\n" "$plugin_name" >&2
printf "No plugin named %s\n" "$plugin_name" >&2
exit 1
fi
else
Expand Down
10 changes: 5 additions & 5 deletions lib/commands/command-info.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
. "$(dirname "$(dirname "$0")")/lib/functions/plugins.bash"

info_command() {
printf "%s:\\n%s\\n\\n" "OS" "$(uname -a)"
printf "%s:\\n%s\\n\\n" "SHELL" "$($SHELL --version)"
printf "%s:\\n%s\\n\\n" "ASDF VERSION" "$(asdf_version)"
printf "%s:\\n%s\\n\\n" "ASDF ENVIRONMENT VARIABLES" "$(env | grep -E "ASDF_DIR|ASDF_DATA_DIR|ASDF_CONFIG_FILE|ASDF_DEFAULT_TOOL_VERSIONS_FILENAME")"
printf "%s:\\n%s\\n\\n" "ASDF INSTALLED PLUGINS" "$(plugin_list_command --urls --refs)"
printf "%s:\n%s\n\n" "OS" "$(uname -a)"
printf "%s:\n%s\n\n" "SHELL" "$($SHELL --version)"
printf "%s:\n%s\n\n" "ASDF VERSION" "$(asdf_version)"
printf "%s:\n%s\n\n" "ASDF ENVIRONMENT VARIABLES" "$(env | grep -E "ASDF_DIR|ASDF_DATA_DIR|ASDF_CONFIG_FILE|ASDF_DEFAULT_TOOL_VERSIONS_FILENAME")"
printf "%s:\n%s\n\n" "ASDF INSTALLED PLUGINS" "$(plugin_list_command --urls --refs)"
}

info_command "$@"
6 changes: 3 additions & 3 deletions lib/commands/command-list.bash
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ list_command() {
if find "$plugins_path" -mindepth 1 -type d &>/dev/null; then
for plugin_path in "$plugins_path"/*/; do
plugin_name=$(basename "$plugin_path")
printf "%s\\n" "$plugin_name"
printf "%s\n" "$plugin_name"
display_installed_versions "$plugin_name" "$query"
done
else
printf "%s\\n" 'No plugins installed'
printf "%s\n" 'No plugins installed'
fi
else
check_if_plugin_exists "$plugin_name"
Expand Down Expand Up @@ -49,7 +49,7 @@ display_installed_versions() {
if [[ "$version" == "$current_version" ]]; then
flag=" *"
fi
printf "%s%s\\n" "$flag" "$version"
printf "%s%s\n" "$flag" "$version"
done
else
display_error ' No versions installed'
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/command-plugin-list-all.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ plugin_list_all_command() {

[[ -d "${plugins_local_path}/${index_plugin_name}" ]] && installed_flag='*'

printf "%s\\t%s\\n" "$index_plugin_name" "$installed_flag$source_url"
printf "%s\t%s\n" "$index_plugin_name" "$installed_flag$source_url"
done
) | awk '{ printf("%-28s", $1); sub(/^[^*]/, " &", $2); $1=""; print $0 }'
else
printf "%s%s\\n" "error: index of plugins not found at " "$plugins_index_path"
printf "%s%s\n" "error: index of plugins not found at " "$plugins_index_path"
fi
}

Expand Down
4 changes: 2 additions & 2 deletions lib/commands/command-plugin-push.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ plugin_push_command() {
local plugin_name=$1
if [ "$plugin_name" = "--all" ]; then
for dir in "$(asdf_data_dir)"/plugins/*/; do
printf "Pushing %s...\\n" "$(basename "$dir")"
printf "Pushing %s...\n" "$(basename "$dir")"
(cd "$dir" && git push)
done
else
local plugin_path
plugin_path=$(get_plugin_path "$plugin_name")
check_if_plugin_exists "$plugin_name"
printf "Pushing %s...\\n" "$plugin_name"
printf "Pushing %s...\n" "$plugin_name"
(cd "$plugin_path" && git push)
fi
}
Expand Down
16 changes: 8 additions & 8 deletions lib/commands/command-plugin-test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ plugin_test_command() {
local TEST_DIR

fail_test() {
printf "FAILED: %s\\n" "$1"
printf "FAILED: %s\n" "$1"
rm -rf "$TEST_DIR"
exit 1
}
Expand Down Expand Up @@ -92,20 +92,20 @@ plugin_test_command() {
local list_all="$plugin_path/bin/list-all"
if grep api.github.com "$list_all" >/dev/null; then
if ! grep Authorization "$list_all" >/dev/null; then
printf "\\nLooks like %s/bin/list-all relies on GitHub releases\\n" "$plugin_name"
printf "but it does not properly sets an Authorization header to prevent\\n"
printf "GitHub API rate limiting.\\n\\n"
printf "See https://github.com/asdf-vm/asdf/blob/master/docs/creating-plugins.md#github-api-rate-limiting\\n"
printf "\nLooks like %s/bin/list-all relies on GitHub releases\n" "$plugin_name"
printf "but it does not properly sets an Authorization header to prevent\n"
printf "GitHub API rate limiting.\n\n"
printf "See https://github.com/asdf-vm/asdf/blob/master/docs/creating-plugins.md#github-api-rate-limiting\n"

fail_test "$plugin_name/bin/list-all does not set GitHub Authorization token"
fi

# test for most common token names we have on plugins. If both are empty show this warning
if [ -z "$OAUTH_TOKEN" ] && [ -z "$GITHUB_API_TOKEN" ]; then
printf "%s/bin/list-all is using GitHub API, just be sure you provide an API Authorization token\\n" "$plugin_name"
printf "via your CI env GITHUB_API_TOKEN. This is the current rate_limit:\\n\\n"
printf "%s/bin/list-all is using GitHub API, just be sure you provide an API Authorization token\n" "$plugin_name"
printf "via your CI env GITHUB_API_TOKEN. This is the current rate_limit:\n\n"
curl -s https://api.github.com/rate_limit
printf "\\n"
printf "\n"
fi
fi

Expand Down
6 changes: 3 additions & 3 deletions lib/commands/command-update.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ update_command() {
cd "$(asdf_dir)" || exit 1

if [ -f asdf_updates_disabled ] || ! git rev-parse --is-inside-work-tree &>/dev/null; then
printf "Update command disabled. Please use the package manager that you used to install asdf to upgrade asdf.\\n"
printf "Update command disabled. Please use the package manager that you used to install asdf to upgrade asdf.\n"
exit 42
else
do_update "$update_to_head"
Expand All @@ -23,7 +23,7 @@ do_update() {
git fetch origin master
git checkout master
git reset --hard origin/master
printf "Updated asdf to latest on the master branch\\n"
printf "Updated asdf to latest on the master branch\n"
else
# Update to latest release
git fetch origin --tags || exit 1
Expand All @@ -38,7 +38,7 @@ do_update() {

# Update
git checkout "$tag" || exit 1
printf "Updated asdf to release %s\\n" "$tag"
printf "Updated asdf to release %s\n" "$tag"
fi
}

Expand Down
6 changes: 3 additions & 3 deletions lib/commands/command-where.bash
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ where_command() {
install_path=$(get_install_path "$plugin_name" "$install_type" "$version")

if [ -d "$install_path" ]; then
printf "%s\\n" "$install_path"
printf "%s\n" "$install_path"
exit 0
else
if [ "$version" = "system" ]; then
printf "System version is selected\\n"
printf "System version is selected\n"
exit 1
else
printf "Version not installed\\n"
printf "Version not installed\n"
exit 1
fi
fi
Expand Down
6 changes: 3 additions & 3 deletions lib/commands/command-which.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ which_command() {
shim_name=$(basename "$1")

if [ -z "$shim_name" ]; then
printf "usage: asdf which <command>\\n"
printf "usage: asdf which <command>\n"
exit 1
fi

Expand All @@ -15,11 +15,11 @@ which_command() {
local executable_path="$3"

if [ ! -x "$executable_path" ]; then
printf "No %s executable found for %s %s\\n" "$shim_name" "$plugin_name" "$version" >&2
printf "No %s executable found for %s %s\n" "$shim_name" "$plugin_name" "$version" >&2
exit 1
fi

printf "%s\\n" "$executable_path"
printf "%s\n" "$executable_path"
exit 0
}

Expand Down
4 changes: 2 additions & 2 deletions lib/commands/reshim.bash
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ remove_obsolete_shims() {
# comm only takes to files, so we write this data to temp files so we can
# pass it to comm.
formatted_shims="$(mktemp "$temp_dir/asdf-command-reshim-formatted-shims.XXXXXX")"
printf "%s\\n" "$shims" >"$formatted_shims"
printf "%s\n" "$shims" >"$formatted_shims"

formatted_exec_names="$(mktemp "$temp_dir/asdf-command-reshim-formatted-exec-names.XXXXXX")"
printf "%s\\n" "$exec_names" >"$formatted_exec_names"
printf "%s\n" "$exec_names" >"$formatted_exec_names"

obsolete_shims=$(comm -23 "$formatted_shims" "$formatted_exec_names")
rm -f "$formatted_exec_names" "$formatted_shims"
Expand Down
Loading

0 comments on commit 3492043

Please sign in to comment.