fix: lint errors from scripts/checkstyle.py (#1385)

Co-authored-by: James Hegedus <jthegedus@hey.com>
This commit is contained in:
Edwin Kofler 2022-12-23 01:53:22 -08:00 committed by GitHub
parent ea18e96bc0
commit 3492043241
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 254 additions and 124 deletions

View File

@ -6,3 +6,6 @@ indent_size = 2
charset = utf-8 charset = utf-8
trim_trailing_whitespace = true trim_trailing_whitespace = true
insert_final_newline = true insert_final_newline = true
[*.py]
indent_size = 4

View File

@ -33,3 +33,15 @@ jobs:
- name: Run shfmt - name: Run shfmt
run: scripts/shfmt.bash 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

View File

@ -1,3 +1,4 @@
bats 1.7.0 bats 1.7.0
shellcheck 0.8.0 shellcheck 0.8.0
shfmt 3.5.1 shfmt 3.5.1
python 3.10.9

View File

@ -44,7 +44,7 @@ plugin_current_command() {
# shellcheck disable=SC2059 # shellcheck disable=SC2059
current_command() { current_command() {
local terminal_format="%-15s %-15s %-10s\\n" local terminal_format="%-15s %-15s %-10s\n"
local exit_status=0 local exit_status=0
local plugin local plugin
@ -75,8 +75,8 @@ check_for_deprecated_plugin() {
local new_script="${plugin_path}/bin/list-legacy-filenames" local new_script="${plugin_path}/bin/list-legacy-filenames"
if [ "$legacy_config" = "yes" ] && [ -f "$deprecated_script" ] && [ ! -f "$new_script" ]; then 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 "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 " asdf plugin-update %s\n\n" "$plugin_name"
fi fi
} }

View File

@ -6,7 +6,7 @@ shim_env_command() {
local env_args=("${@:3}") local env_args=("${@:3}")
if [ -z "$shim_name" ]; then if [ -z "$shim_name" ]; then
printf "usage: asdf env <command>\\n" printf "usage: asdf env <command>\n"
exit 1 exit 1
fi fi

View File

@ -6,7 +6,7 @@ shim_exec_command() {
local shim_args=("${@:2}") local shim_args=("${@:2}")
if [ -z "$shim_name" ]; then if [ -z "$shim_name" ]; then
printf "usage: asdf exec <command>\\n" printf "usage: asdf exec <command>\n"
exit 1 exit 1
fi fi
@ -16,7 +16,7 @@ shim_exec_command() {
local executable_path="$3" local executable_path="$3"
if [ ! -x "$executable_path" ]; then 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 exit 2
fi fi

View File

@ -8,8 +8,8 @@ shell_command() {
shift shift
if [ "$#" -lt "2" ]; then if [ "$#" -lt "2" ]; then
printf "Usage: asdf shell <name> {<version>|--unset}\\n" >&2 printf "Usage: asdf shell <name> {<version>|--unset}\n" >&2
printf "false\\n" printf "false\n"
exit 1 exit 1
fi fi
@ -23,7 +23,7 @@ shell_command() {
if [ "$version" = "--unset" ]; then if [ "$version" = "--unset" ]; then
case "$asdf_shell" in case "$asdf_shell" in
fish) fish)
printf "set -e %s\\n" "$version_env_var" printf "set -e %s\n" "$version_env_var"
;; ;;
elvish) elvish)
# Elvish doesn't have a `source` command, and eval is banned, so the # Elvish doesn't have a `source` command, and eval is banned, so the
@ -32,7 +32,7 @@ shell_command() {
printf "unset-env\n%s" "$version_env_var" printf "unset-env\n%s" "$version_env_var"
;; ;;
*) *)
printf "unset %s\\n" "$version_env_var" printf "unset %s\n" "$version_env_var"
;; ;;
esac esac
exit 0 exit 0
@ -42,13 +42,13 @@ shell_command() {
fi fi
if ! (check_if_version_exists "$plugin" "$version"); then if ! (check_if_version_exists "$plugin" "$version"); then
version_not_installed_text "$plugin" "$version" 1>&2 version_not_installed_text "$plugin" "$version" 1>&2
printf "false\\n" printf "false\n"
exit 1 exit 1
fi fi
case "$asdf_shell" in case "$asdf_shell" in
fish) fish)
printf "set -gx %s \"%s\"\\n" "$version_env_var" "$version" printf "set -gx %s \"%s\"\n" "$version_env_var" "$version"
;; ;;
elvish) elvish)
# Elvish doesn't have a `source` command, and eval is banned, so the # Elvish doesn't have a `source` command, and eval is banned, so the
@ -57,7 +57,7 @@ shell_command() {
printf "set-env\n%s\n%s" "$version_env_var" "$version" 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 esac
} }

View File

@ -3,7 +3,7 @@
. "$(dirname "$(dirname "$0")")/lib/functions/versions.bash" . "$(dirname "$(dirname "$0")")/lib/functions/versions.bash"
asdf_help() { asdf_help() {
printf "version: %s\\n\\n" "$(asdf_version)" printf "version: %s\n\n" "$(asdf_version)"
cat "$(asdf_dir)/help.txt" cat "$(asdf_dir)/help.txt"
} }
@ -23,7 +23,7 @@ asdf_extension_cmds() {
ext_cmd_path="$plugin_path/lib/commands" ext_cmd_path="$plugin_path/lib/commands"
ext_cmds="$(find "$ext_cmd_path" -name "command*.bash" 2>/dev/null)" ext_cmds="$(find "$ext_cmd_path" -name "command*.bash" 2>/dev/null)"
if [[ -n $ext_cmds ]]; then if [[ -n $ext_cmds ]]; then
printf "\\nPLUGIN %s\\n" "$plugin" printf "\nPLUGIN %s\n" "$plugin"
for ext_cmd in $ext_cmds; do for ext_cmd in $ext_cmds; do
ext_cmd_name="$(basename "$ext_cmd")" ext_cmd_name="$(basename "$ext_cmd")"
sed "s/-/ /g;s/.bash//;s/command-*/ asdf $plugin/;" <<<"$ext_cmd_name" sed "s/-/ /g;s/.bash//;s/command-*/ asdf $plugin/;" <<<"$ext_cmd_name"
@ -78,11 +78,11 @@ help_command() {
(print_plugin_help "$plugin_path") (print_plugin_help "$plugin_path")
fi fi
else else
printf "No documentation for plugin %s\\n" "$plugin_name" >&2 printf "No documentation for plugin %s\n" "$plugin_name" >&2
exit 1 exit 1
fi fi
else else
printf "No plugin named %s\\n" "$plugin_name" >&2 printf "No plugin named %s\n" "$plugin_name" >&2
exit 1 exit 1
fi fi
else else

View File

@ -3,11 +3,11 @@
. "$(dirname "$(dirname "$0")")/lib/functions/plugins.bash" . "$(dirname "$(dirname "$0")")/lib/functions/plugins.bash"
info_command() { info_command() {
printf "%s:\\n%s\\n\\n" "OS" "$(uname -a)" printf "%s:\n%s\n\n" "OS" "$(uname -a)"
printf "%s:\\n%s\\n\\n" "SHELL" "$($SHELL --version)" 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 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 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" "ASDF INSTALLED PLUGINS" "$(plugin_list_command --urls --refs)"
} }
info_command "$@" info_command "$@"

View File

@ -11,11 +11,11 @@ list_command() {
if find "$plugins_path" -mindepth 1 -type d &>/dev/null; then if find "$plugins_path" -mindepth 1 -type d &>/dev/null; then
for plugin_path in "$plugins_path"/*/; do for plugin_path in "$plugins_path"/*/; do
plugin_name=$(basename "$plugin_path") plugin_name=$(basename "$plugin_path")
printf "%s\\n" "$plugin_name" printf "%s\n" "$plugin_name"
display_installed_versions "$plugin_name" "$query" display_installed_versions "$plugin_name" "$query"
done done
else else
printf "%s\\n" 'No plugins installed' printf "%s\n" 'No plugins installed'
fi fi
else else
check_if_plugin_exists "$plugin_name" check_if_plugin_exists "$plugin_name"
@ -49,7 +49,7 @@ display_installed_versions() {
if [[ "$version" == "$current_version" ]]; then if [[ "$version" == "$current_version" ]]; then
flag=" *" flag=" *"
fi fi
printf "%s%s\\n" "$flag" "$version" printf "%s%s\n" "$flag" "$version"
done done
else else
display_error ' No versions installed' display_error ' No versions installed'

View File

@ -18,11 +18,11 @@ plugin_list_all_command() {
[[ -d "${plugins_local_path}/${index_plugin_name}" ]] && installed_flag='*' [[ -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 done
) | awk '{ printf("%-28s", $1); sub(/^[^*]/, " &", $2); $1=""; print $0 }' ) | awk '{ printf("%-28s", $1); sub(/^[^*]/, " &", $2); $1=""; print $0 }'
else 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 fi
} }

View File

@ -4,14 +4,14 @@ plugin_push_command() {
local plugin_name=$1 local plugin_name=$1
if [ "$plugin_name" = "--all" ]; then if [ "$plugin_name" = "--all" ]; then
for dir in "$(asdf_data_dir)"/plugins/*/; do for dir in "$(asdf_data_dir)"/plugins/*/; do
printf "Pushing %s...\\n" "$(basename "$dir")" printf "Pushing %s...\n" "$(basename "$dir")"
(cd "$dir" && git push) (cd "$dir" && git push)
done done
else else
local plugin_path local plugin_path
plugin_path=$(get_plugin_path "$plugin_name") plugin_path=$(get_plugin_path "$plugin_name")
check_if_plugin_exists "$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) (cd "$plugin_path" && git push)
fi fi
} }

View File

@ -53,7 +53,7 @@ plugin_test_command() {
local TEST_DIR local TEST_DIR
fail_test() { fail_test() {
printf "FAILED: %s\\n" "$1" printf "FAILED: %s\n" "$1"
rm -rf "$TEST_DIR" rm -rf "$TEST_DIR"
exit 1 exit 1
} }
@ -92,20 +92,20 @@ plugin_test_command() {
local list_all="$plugin_path/bin/list-all" local list_all="$plugin_path/bin/list-all"
if grep api.github.com "$list_all" >/dev/null; then if grep api.github.com "$list_all" >/dev/null; then
if ! grep Authorization "$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 "\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 "but it does not properly sets an Authorization header to prevent\n"
printf "GitHub API rate limiting.\\n\\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 "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" fail_test "$plugin_name/bin/list-all does not set GitHub Authorization token"
fi fi
# test for most common token names we have on plugins. If both are empty show this warning # 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 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 "%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 "via your CI env GITHUB_API_TOKEN. This is the current rate_limit:\n\n"
curl -s https://api.github.com/rate_limit curl -s https://api.github.com/rate_limit
printf "\\n" printf "\n"
fi fi
fi fi

View File

@ -7,7 +7,7 @@ update_command() {
cd "$(asdf_dir)" || exit 1 cd "$(asdf_dir)" || exit 1
if [ -f asdf_updates_disabled ] || ! git rev-parse --is-inside-work-tree &>/dev/null; then 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 exit 42
else else
do_update "$update_to_head" do_update "$update_to_head"
@ -23,7 +23,7 @@ do_update() {
git fetch origin master git fetch origin master
git checkout master git checkout master
git reset --hard origin/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 else
# Update to latest release # Update to latest release
git fetch origin --tags || exit 1 git fetch origin --tags || exit 1
@ -38,7 +38,7 @@ do_update() {
# Update # Update
git checkout "$tag" || exit 1 git checkout "$tag" || exit 1
printf "Updated asdf to release %s\\n" "$tag" printf "Updated asdf to release %s\n" "$tag"
fi fi
} }

View File

@ -34,14 +34,14 @@ where_command() {
install_path=$(get_install_path "$plugin_name" "$install_type" "$version") install_path=$(get_install_path "$plugin_name" "$install_type" "$version")
if [ -d "$install_path" ]; then if [ -d "$install_path" ]; then
printf "%s\\n" "$install_path" printf "%s\n" "$install_path"
exit 0 exit 0
else else
if [ "$version" = "system" ]; then if [ "$version" = "system" ]; then
printf "System version is selected\\n" printf "System version is selected\n"
exit 1 exit 1
else else
printf "Version not installed\\n" printf "Version not installed\n"
exit 1 exit 1
fi fi
fi fi

View File

@ -5,7 +5,7 @@ which_command() {
shim_name=$(basename "$1") shim_name=$(basename "$1")
if [ -z "$shim_name" ]; then if [ -z "$shim_name" ]; then
printf "usage: asdf which <command>\\n" printf "usage: asdf which <command>\n"
exit 1 exit 1
fi fi
@ -15,11 +15,11 @@ which_command() {
local executable_path="$3" local executable_path="$3"
if [ ! -x "$executable_path" ]; then 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 exit 1
fi fi
printf "%s\\n" "$executable_path" printf "%s\n" "$executable_path"
exit 0 exit 0
} }

View File

@ -142,10 +142,10 @@ remove_obsolete_shims() {
# comm only takes to files, so we write this data to temp files so we can # comm only takes to files, so we write this data to temp files so we can
# pass it to comm. # pass it to comm.
formatted_shims="$(mktemp "$temp_dir/asdf-command-reshim-formatted-shims.XXXXXX")" 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")" 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") obsolete_shims=$(comm -23 "$formatted_shims" "$formatted_exec_names")
rm -f "$formatted_exec_names" "$formatted_shims" rm -f "$formatted_exec_names" "$formatted_shims"

View File

@ -6,7 +6,7 @@ handle_failure() {
handle_cancel() { handle_cancel() {
local install_path="$1" local install_path="$1"
printf "\\nreceived sigint, cleaning up" printf "\nreceived sigint, cleaning up"
handle_failure "$install_path" handle_failure "$install_path"
} }
@ -32,7 +32,7 @@ get_concurrency() {
elif [ -f /proc/cpuinfo ]; then elif [ -f /proc/cpuinfo ]; then
grep -c processor /proc/cpuinfo grep -c processor /proc/cpuinfo
else else
printf "1\\n" printf "1\n"
fi fi
} }
@ -55,7 +55,7 @@ install_one_local_tool() {
install_tool_version "$plugin_name" "$plugin_version" install_tool_version "$plugin_name" "$plugin_version"
done done
else else
printf "No versions specified for %s in config files or environment\\n" "$plugin_name" printf "No versions specified for %s in config files or environment\n" "$plugin_name"
exit 1 exit 1
fi fi
} }
@ -85,7 +85,7 @@ install_local_tool_versions() {
fi fi
if [ -z "$plugins_installed" ]; then if [ -z "$plugins_installed" ]; then
printf "Install plugins first to be able to install tools\\n" printf "Install plugins first to be able to install tools\n"
exit 1 exit 1
fi fi
@ -122,9 +122,9 @@ install_local_tool_versions() {
fi fi
if [ -z "$some_tools_installed" ]; then if [ -z "$some_tools_installed" ]; then
printf "Either specify a tool & version in the command\\n" printf "Either specify a tool & version in the command\n"
printf "OR add .tool-versions file in this directory\\n" printf "OR add .tool-versions file in this directory\n"
printf "or in a parent directory\\n" printf "or in a parent directory\n"
exit 1 exit 1
fi fi
} }
@ -180,7 +180,7 @@ install_tool_version() {
trap 'handle_cancel $install_path' INT trap 'handle_cancel $install_path' INT
if [ -d "$install_path" ]; then if [ -d "$install_path" ]; then
printf "%s %s is already installed\\n" "$plugin_name" "$full_version" printf "%s %s is already installed\n" "$plugin_name" "$full_version"
else else
if [ -f "${plugin_path}/bin/download" ]; then if [ -f "${plugin_path}/bin/download" ]; then

View File

@ -28,7 +28,7 @@ plugin_list_command() {
printf "%s" "$plugin_name" printf "%s" "$plugin_name"
if [ -n "$show_repo" ]; then if [ -n "$show_repo" ]; then
printf "\\t%s" "$(git --git-dir "$plugin_path/.git" remote get-url origin 2>/dev/null)" printf "\t%s" "$(git --git-dir "$plugin_path/.git" remote get-url origin 2>/dev/null)"
fi fi
if [ -n "$show_ref" ]; then if [ -n "$show_ref" ]; then
@ -36,10 +36,10 @@ plugin_list_command() {
local gitref local gitref
branch=$(git --git-dir "$plugin_path/.git" rev-parse --abbrev-ref HEAD 2>/dev/null) branch=$(git --git-dir "$plugin_path/.git" rev-parse --abbrev-ref HEAD 2>/dev/null)
gitref=$(git --git-dir "$plugin_path/.git" rev-parse --short HEAD 2>/dev/null) gitref=$(git --git-dir "$plugin_path/.git" rev-parse --short HEAD 2>/dev/null)
printf "\\t%s\\t%s" "$branch" "$gitref" printf "\t%s\t%s" "$branch" "$gitref"
fi fi
printf "\\n" printf "\n"
done done
) | awk '{ if (NF > 1) { printf("%-28s", $1) ; $1="" }; print $0}' ) | awk '{ if (NF > 1) { printf("%-28s", $1) ; $1="" }; print $0}'
else else
@ -145,7 +145,7 @@ update_plugin() {
asdf_run_hook "pre_asdf_plugin_update" "$plugin_name" asdf_run_hook "pre_asdf_plugin_update" "$plugin_name"
asdf_run_hook "pre_asdf_plugin_update_${plugin_name}" asdf_run_hook "pre_asdf_plugin_update_${plugin_name}"
printf "Updating %s to %s\\n" "$plugin_name" "$gitref" printf "Updating %s to %s\n" "$plugin_name" "$gitref"
git "${common_git_options[@]}" fetch --prune --update-head-ok origin "$gitref:$gitref" git "${common_git_options[@]}" fetch --prune --update-head-ok origin "$gitref:$gitref"
prev_ref=$(git "${common_git_options[@]}" rev-parse --short HEAD) prev_ref=$(git "${common_git_options[@]}" rev-parse --short HEAD)

View File

@ -4,9 +4,9 @@ version_command() {
if [ "$#" -lt "3" ]; then if [ "$#" -lt "3" ]; then
if [ "$cmd" = "global" ]; then if [ "$cmd" = "global" ]; then
printf "Usage: asdf global <name> <version>\\n" printf "Usage: asdf global <name> <version>\n"
else else
printf "Usage: asdf local <name> <version>\\n" printf "Usage: asdf local <name> <version>\n"
fi fi
exit 1 exit 1
fi fi
@ -68,7 +68,7 @@ version_command() {
[[ -n "$(tail -c1 "$file")" && -f "$file" ]] && printf '\n' >>"$file" [[ -n "$(tail -c1 "$file")" && -f "$file" ]] && printf '\n' >>"$file"
# Add a new version line to the end of the file # Add a new version line to the end of the file
printf "%s %s\\n" "$plugin_name" "${resolved_versions[*]}" >>"$file" printf "%s %s\n" "$plugin_name" "${resolved_versions[*]}" >>"$file"
fi fi
} }
@ -92,9 +92,9 @@ list_all_command() {
if [[ $return_code -ne 0 ]]; then if [[ $return_code -ne 0 ]]; then
# Printing all output to allow plugin to handle error formatting # Printing all output to allow plugin to handle error formatting
printf "Plugin %s's list-all callback script failed with output:\\n" "${plugin_name}" >&2 printf "Plugin %s's list-all callback script failed with output:\n" "${plugin_name}" >&2
printf "%s\\n" "$(cat "$std_err_file")" >&2 printf "%s\n" "$(cat "$std_err_file")" >&2
printf "%s\\n" "$(cat "$std_out_file")" >&2 printf "%s\n" "$(cat "$std_out_file")" >&2
rm "$std_out_file" "$std_err_file" rm "$std_out_file" "$std_err_file"
exit 1 exit 1
fi fi
@ -115,7 +115,7 @@ list_all_command() {
IFS=' ' read -r -a versions_list <<<"$output" IFS=' ' read -r -a versions_list <<<"$output"
for version in "${versions_list[@]}"; do for version in "${versions_list[@]}"; do
printf "%s\\n" "${version}" printf "%s\n" "${version}"
done done
# Remove temp files if they still exist # Remove temp files if they still exist
@ -144,7 +144,7 @@ latest_command() {
versions=$("${plugin_path}"/bin/latest-stable "$query") versions=$("${plugin_path}"/bin/latest-stable "$query")
if [ -z "${versions}" ]; then if [ -z "${versions}" ]; then
# this branch requires this print to mimic the error from the list-all branch # this branch requires this print to mimic the error from the list-all branch
printf "No compatible versions available (%s %s)\\n" "$plugin_name" "$query" >&2 printf "No compatible versions available (%s %s)\n" "$plugin_name" "$query" >&2
exit 1 exit 1
fi fi
else else
@ -158,7 +158,7 @@ latest_command() {
fi fi
fi fi
printf "%s\\n" "$versions" printf "%s\n" "$versions"
} }
latest_all() { latest_all() {
@ -198,10 +198,10 @@ latest_all() {
if [ -n "$installed_versions" ] && printf '%s\n' "$installed_versions" | grep -q "^$version\$"; then if [ -n "$installed_versions" ] && printf '%s\n' "$installed_versions" | grep -q "^$version\$"; then
installed_status="installed" installed_status="installed"
fi fi
printf "%s\\t%s\\t%s\\n" "$plugin_name" "$version" "$installed_status" printf "%s\t%s\t%s\n" "$plugin_name" "$version" "$installed_status"
done done
else else
printf "%s\\n" 'No plugins installed' printf "%s\n" 'No plugins installed'
fi fi
exit 0 exit 0
} }

View File

@ -13,9 +13,9 @@ asdf_version() {
version="v$(cat "$(asdf_dir)/version.txt")" version="v$(cat "$(asdf_dir)/version.txt")"
if [ -d "$(asdf_dir)/.git" ]; then if [ -d "$(asdf_dir)/.git" ]; then
git_rev="$(git --git-dir "$(asdf_dir)/.git" rev-parse --short HEAD)" git_rev="$(git --git-dir "$(asdf_dir)/.git" rev-parse --short HEAD)"
printf "%s-%s\\n" "$version" "$git_rev" printf "%s-%s\n" "$version" "$git_rev"
else else
printf "%s\\n" "$version" printf "%s\n" "$version"
fi fi
} }
@ -29,11 +29,11 @@ asdf_dir() {
) )
fi fi
printf "%s\\n" "$ASDF_DIR" printf "%s\n" "$ASDF_DIR"
} }
asdf_repository_url() { asdf_repository_url() {
printf "https://github.com/asdf-vm/asdf-plugins.git\\n" printf "https://github.com/asdf-vm/asdf-plugins.git\n"
} }
asdf_data_dir() { asdf_data_dir() {
@ -47,7 +47,7 @@ asdf_data_dir() {
data_dir=$(asdf_dir) data_dir=$(asdf_dir)
fi fi
printf "%s\\n" "$data_dir" printf "%s\n" "$data_dir"
} }
get_install_path() { get_install_path() {
@ -61,11 +61,11 @@ get_install_path() {
mkdir -p "${install_dir}/${plugin}" mkdir -p "${install_dir}/${plugin}"
if [ "$install_type" = "version" ]; then if [ "$install_type" = "version" ]; then
printf "%s/%s/%s\\n" "$install_dir" "$plugin" "$version" printf "%s/%s/%s\n" "$install_dir" "$plugin" "$version"
elif [ "$install_type" = "path" ]; then elif [ "$install_type" = "path" ]; then
printf "%s\\n" "$version" printf "%s\n" "$version"
else else
printf "%s/%s/%s-%s\\n" "$install_dir" "$plugin" "$install_type" "$version" printf "%s/%s/%s-%s\n" "$install_dir" "$plugin" "$install_type" "$version"
fi fi
} }
@ -80,11 +80,11 @@ get_download_path() {
mkdir -p "${download_dir}/${plugin}" mkdir -p "${download_dir}/${plugin}"
if [ "$install_type" = "version" ]; then if [ "$install_type" = "version" ]; then
printf "%s/%s/%s\\n" "$download_dir" "$plugin" "$version" printf "%s/%s/%s\n" "$download_dir" "$plugin" "$version"
elif [ "$install_type" = "path" ]; then elif [ "$install_type" = "path" ]; then
return return
else else
printf "%s/%s/%s-%s\\n" "$download_dir" "$plugin" "$install_type" "$version" printf "%s/%s/%s-%s\n" "$download_dir" "$plugin" "$install_type" "$version"
fi fi
} }
@ -137,19 +137,19 @@ version_not_installed_text() {
local plugin_name=$1 local plugin_name=$1
local version=$2 local version=$2
printf "version %s is not installed for %s\\n" "$version" "$plugin_name" printf "version %s is not installed for %s\n" "$version" "$plugin_name"
} }
get_plugin_path() { get_plugin_path() {
if [ -n "$1" ]; then if [ -n "$1" ]; then
printf "%s\\n" "$(asdf_data_dir)/plugins/$1" printf "%s\n" "$(asdf_data_dir)/plugins/$1"
else else
printf "%s\\n" "$(asdf_data_dir)/plugins" printf "%s\n" "$(asdf_data_dir)/plugins"
fi fi
} }
display_error() { display_error() {
printf "%s\\n" "$1" >&2 printf "%s\n" "$1" >&2
} }
get_version_in_dir() { get_version_in_dir() {
@ -163,7 +163,7 @@ get_version_in_dir() {
asdf_version=$(parse_asdf_version_file "$search_path/$file_name" "$plugin_name") asdf_version=$(parse_asdf_version_file "$search_path/$file_name" "$plugin_name")
if [ -n "$asdf_version" ]; then if [ -n "$asdf_version" ]; then
printf "%s\\n" "$asdf_version|$search_path/$file_name" printf "%s\n" "$asdf_version|$search_path/$file_name"
return 0 return 0
fi fi
@ -172,7 +172,7 @@ get_version_in_dir() {
legacy_version=$(parse_legacy_version_file "$search_path/$filename" "$plugin_name") legacy_version=$(parse_legacy_version_file "$search_path/$filename" "$plugin_name")
if [ -n "$legacy_version" ]; then if [ -n "$legacy_version" ]; then
printf "%s\\n" "$legacy_version|$search_path/$filename" printf "%s\n" "$legacy_version|$search_path/$filename"
return 0 return 0
fi fi
done done
@ -190,10 +190,10 @@ find_versions() {
version=$(get_version_from_env "$plugin_name") version=$(get_version_from_env "$plugin_name")
if [ -n "$version" ]; then if [ -n "$version" ]; then
local upcase_name local upcase_name
upcase_name=$(printf "%s\\n" "$plugin_name" | tr '[:lower:]-' '[:upper:]_') upcase_name=$(printf "%s\n" "$plugin_name" | tr '[:lower:]-' '[:upper:]_')
local version_env_var="ASDF_${upcase_name}_VERSION" local version_env_var="ASDF_${upcase_name}_VERSION"
printf "%s\\n" "$version|$version_env_var environment variable" printf "%s\n" "$version|$version_env_var environment variable"
return 0 return 0
fi fi
@ -212,7 +212,7 @@ find_versions() {
while [ "$search_path" != "/" ]; do while [ "$search_path" != "/" ]; do
version=$(get_version_in_dir "$plugin_name" "$search_path" "$legacy_filenames") version=$(get_version_in_dir "$plugin_name" "$search_path" "$legacy_filenames")
if [ -n "$version" ]; then if [ -n "$version" ]; then
printf "%s\\n" "$version" printf "%s\n" "$version"
return 0 return 0
fi fi
search_path=$(dirname "$search_path") search_path=$(dirname "$search_path")
@ -223,7 +223,7 @@ find_versions() {
if [ -f "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" ]; then if [ -f "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" ]; then
versions=$(parse_asdf_version_file "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" "$plugin_name") versions=$(parse_asdf_version_file "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" "$plugin_name")
if [ -n "$versions" ]; then if [ -n "$versions" ]; then
printf "%s\\n" "$versions|$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" printf "%s\n" "$versions|$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME"
return 0 return 0
fi fi
fi fi
@ -231,16 +231,16 @@ find_versions() {
display_no_version_set() { display_no_version_set() {
local plugin_name=$1 local plugin_name=$1
printf "No version is set for %s; please run \`asdf <global | shell | local> %s <version>\`\\n" "$plugin_name" "$plugin_name" printf "No version is set for %s; please run \`asdf <global | shell | local> %s <version>\`\n" "$plugin_name" "$plugin_name"
} }
get_version_from_env() { get_version_from_env() {
local plugin_name=$1 local plugin_name=$1
local upcase_name local upcase_name
upcase_name=$(printf "%s\\n" "$plugin_name" | tr '[:lower:]-' '[:upper:]_') upcase_name=$(printf "%s\n" "$plugin_name" | tr '[:lower:]-' '[:upper:]_')
local version_env_var="ASDF_${upcase_name}_VERSION" local version_env_var="ASDF_${upcase_name}_VERSION"
local version=${!version_env_var:-} local version=${!version_env_var:-}
printf "%s\\n" "$version" printf "%s\n" "$version"
} }
find_install_path() { find_install_path() {
@ -251,7 +251,7 @@ find_install_path() {
IFS=':' read -a version_info <<<"$version" IFS=':' read -a version_info <<<"$version"
if [ "$version" = "system" ]; then if [ "$version" = "system" ]; then
printf "\\n" printf "\n"
elif [ "${version_info[0]}" = "ref" ]; then elif [ "${version_info[0]}" = "ref" ]; then
local install_type="${version_info[0]}" local install_type="${version_info[0]}"
local version="${version_info[1]}" local version="${version_info[1]}"
@ -263,7 +263,7 @@ find_install_path() {
# And then use the binaries there # And then use the binaries there
local install_type="path" local install_type="path"
local version="path" local version="path"
printf "%s\\n" "${version_info[1]}" printf "%s\n" "${version_info[1]}"
else else
local install_type="version" local install_type="version"
local version="${version_info[0]}" local version="${version_info[0]}"
@ -281,12 +281,12 @@ get_custom_executable_path() {
cmd=$(basename "$executable_path") cmd=$(basename "$executable_path")
local relative_path local relative_path
# shellcheck disable=SC2001 # shellcheck disable=SC2001
relative_path=$(printf "%s\\n" "$executable_path" | sed -e "s|${install_path}/||") relative_path=$(printf "%s\n" "$executable_path" | sed -e "s|${install_path}/||")
relative_path="$("${plugin_path}/bin/exec-path" "$install_path" "$cmd" "$relative_path")" relative_path="$("${plugin_path}/bin/exec-path" "$install_path" "$cmd" "$relative_path")"
executable_path="$install_path/$relative_path" executable_path="$install_path/$relative_path"
fi fi
printf "%s\\n" "$executable_path" printf "%s\n" "$executable_path"
} }
get_executable_path() { get_executable_path() {
@ -304,11 +304,11 @@ get_executable_path() {
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
return 1 return 1
fi fi
printf "%s\\n" "$cmd_path" printf "%s\n" "$cmd_path"
else else
local install_path local install_path
install_path=$(find_install_path "$plugin_name" "$version") install_path=$(find_install_path "$plugin_name" "$version")
printf "%s\\n" "${install_path}"/"${executable_path}" printf "%s\n" "${install_path}"/"${executable_path}"
fi fi
} }
@ -320,7 +320,7 @@ parse_asdf_version_file() {
local version local version
version=$(strip_tool_version_comments "$file_path" | grep "^${plugin_name} " | sed -e "s/^${plugin_name} //") version=$(strip_tool_version_comments "$file_path" | grep "^${plugin_name} " | sed -e "s/^${plugin_name} //")
if [ -n "$version" ]; then if [ -n "$version" ]; then
printf "%s\\n" "$version" printf "%s\n" "$version"
return 0 return 0
fi fi
fi fi
@ -353,7 +353,7 @@ get_preset_version_for() {
local version local version
version=$(cut -d '|' -f 1 <<<"$version_and_path") version=$(cut -d '|' -f 1 <<<"$version_and_path")
printf "%s\\n" "$version" printf "%s\n" "$version"
} }
get_asdf_config_value_from_file() { get_asdf_config_value_from_file() {
@ -367,7 +367,7 @@ get_asdf_config_value_from_file() {
local result local result
result=$(grep -E "^\s*$key\s*=\s*" "$config_path" | head | sed -e 's/^[^=]*= *//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') result=$(grep -E "^\s*$key\s*=\s*" "$config_path" | head | sed -e 's/^[^=]*= *//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [ -n "$result" ]; then if [ -n "$result" ]; then
printf "%s\\n" "$result" printf "%s\n" "$result"
return 0 return 0
fi fi
@ -414,7 +414,7 @@ initialize_or_update_repository() {
disable_plugin_short_name_repo="$(get_asdf_config_value "disable_plugin_short_name_repository")" disable_plugin_short_name_repo="$(get_asdf_config_value "disable_plugin_short_name_repository")"
if [ "yes" == "$disable_plugin_short_name_repo" ]; then if [ "yes" == "$disable_plugin_short_name_repo" ]; then
printf "Short-name plugin repository is disabled\\n" >&2 printf "Short-name plugin repository is disabled\n" >&2
exit 1 exit 1
fi fi
@ -454,7 +454,7 @@ find_file_upwards() {
search_path=$(pwd) search_path=$(pwd)
while [ "$search_path" != "/" ]; do while [ "$search_path" != "/" ]; do
if [ -f "$search_path/$name" ]; then if [ -f "$search_path/$name" ]; then
printf "%s\\n" "${search_path}/$name" printf "%s\n" "${search_path}/$name"
return 0 return 0
fi fi
search_path=$(dirname "$search_path") search_path=$(dirname "$search_path")
@ -475,12 +475,12 @@ resolve_symlink() {
# as relative # as relative
case $resolved_path in case $resolved_path in
/*) /*)
printf "%s\\n" "$resolved_path" printf "%s\n" "$resolved_path"
;; ;;
*) *)
( (
cd "$(dirname "$symlink")" || exit 1 cd "$(dirname "$symlink")" || exit 1
printf "%s\\n" "$PWD/$resolved_path" printf "%s\n" "$PWD/$resolved_path"
) )
;; ;;
esac esac
@ -508,7 +508,7 @@ list_plugin_bin_paths() {
else else
local space_separated_list_of_bin_paths="bin" local space_separated_list_of_bin_paths="bin"
fi fi
printf "%s\\n" "$space_separated_list_of_bin_paths" printf "%s\n" "$space_separated_list_of_bin_paths"
} }
list_plugin_exec_paths() { list_plugin_exec_paths() {
@ -531,7 +531,7 @@ list_plugin_exec_paths() {
local plugin_shims_path local plugin_shims_path
plugin_shims_path=$(get_plugin_path "$plugin_name")/shims plugin_shims_path=$(get_plugin_path "$plugin_name")/shims
if [ -d "$plugin_shims_path" ]; then if [ -d "$plugin_shims_path" ]; then
printf "%s\\n" "$plugin_shims_path" printf "%s\n" "$plugin_shims_path"
fi fi
space_separated_list_of_bin_paths="$(list_plugin_bin_paths "$plugin_name" "$version" "$install_type")" space_separated_list_of_bin_paths="$(list_plugin_bin_paths "$plugin_name" "$version" "$install_type")"
@ -541,7 +541,7 @@ list_plugin_exec_paths() {
install_path=$(get_install_path "$plugin_name" "$install_type" "$version") install_path=$(get_install_path "$plugin_name" "$install_type" "$version")
for bin_path in "${all_bin_paths[@]}"; do for bin_path in "${all_bin_paths[@]}"; do
printf "%s\\n" "$install_path/$bin_path" printf "%s\n" "$install_path/$bin_path"
done done
} }
@ -603,7 +603,7 @@ plugin_executables() {
for bin_path in "${all_bin_paths[@]}"; do for bin_path in "${all_bin_paths[@]}"; do
for executable_file in "$bin_path"/*; do for executable_file in "$bin_path"/*; do
if is_executable "$executable_file"; then if is_executable "$executable_file"; then
printf "%s\\n" "$executable_file" printf "%s\n" "$executable_file"
fi fi
done done
done done
@ -631,7 +631,7 @@ shim_plugin_versions() {
if [ -x "$shim_path" ]; then if [ -x "$shim_path" ]; then
grep "# asdf-plugin: " "$shim_path" 2>/dev/null | sed -e "s/# asdf-plugin: //" | uniq grep "# asdf-plugin: " "$shim_path" 2>/dev/null | sed -e "s/# asdf-plugin: //" | uniq
else else
printf "asdf: unknown shim %s\\n" "$executable_name" printf "asdf: unknown shim %s\n" "$executable_name"
return 1 return 1
fi fi
} }
@ -644,7 +644,7 @@ shim_plugins() {
if [ -x "$shim_path" ]; then if [ -x "$shim_path" ]; then
grep "# asdf-plugin: " "$shim_path" 2>/dev/null | sed -e "s/# asdf-plugin: //" | cut -d' ' -f 1 | uniq grep "# asdf-plugin: " "$shim_path" 2>/dev/null | sed -e "s/# asdf-plugin: //" | cut -d' ' -f 1 | uniq
else else
printf "asdf: unknown shim %s\\n" "$executable_name" printf "asdf: unknown shim %s\n" "$executable_name"
return 1 return 1
fi fi
} }
@ -682,7 +682,7 @@ get_shim_versions() {
preset_versions() { preset_versions() {
shim_name=$1 shim_name=$1
shim_plugin_versions "${shim_name}" | cut -d' ' -f 1 | uniq | xargs -IPLUGIN bash -c ". $(asdf_dir)/lib/utils.bash; printf \"%s %s\\n\" PLUGIN \$(get_preset_version_for PLUGIN)" shim_plugin_versions "${shim_name}" | cut -d' ' -f 1 | uniq | xargs -IPLUGIN bash -c ". $(asdf_dir)/lib/utils.bash; printf \"%s %s\n\" PLUGIN \$(get_preset_version_for PLUGIN)"
} }
select_from_preset_version() { select_from_preset_version() {
@ -693,7 +693,7 @@ select_from_preset_version() {
shim_versions=$(get_shim_versions "$shim_name") shim_versions=$(get_shim_versions "$shim_name")
if [ -n "$shim_versions" ]; then if [ -n "$shim_versions" ]; then
preset_versions=$(preset_versions "$shim_name") preset_versions=$(preset_versions "$shim_name")
grep -F "$shim_versions" <<<"$preset_versions" | head -n 1 | xargs -IVERSION printf "%s\\n" VERSION grep -F "$shim_versions" <<<"$preset_versions" | head -n 1 | xargs -IVERSION printf "%s\n" VERSION
fi fi
} }
@ -728,10 +728,10 @@ select_version() {
IFS=' ' read -r plugin_shim_name plugin_shim_version <<<"$plugin_and_version" IFS=' ' read -r plugin_shim_name plugin_shim_version <<<"$plugin_and_version"
if [[ "$plugin_name" == "$plugin_shim_name" ]]; then if [[ "$plugin_name" == "$plugin_shim_name" ]]; then
if [[ "$plugin_version" == "$plugin_shim_version" ]]; then if [[ "$plugin_version" == "$plugin_shim_version" ]]; then
printf "%s\\n" "$plugin_name $plugin_version" printf "%s\n" "$plugin_name $plugin_version"
return return
elif [[ "$plugin_version" == "path:"* ]]; then elif [[ "$plugin_version" == "path:"* ]]; then
printf "%s\\n" "$plugin_name $plugin_version" printf "%s\n" "$plugin_name $plugin_version"
return return
fi fi
fi fi
@ -746,7 +746,7 @@ with_shim_executable() {
local shim_exec="${2}" local shim_exec="${2}"
if [ ! -f "$(asdf_data_dir)/shims/${shim_name}" ]; then if [ ! -f "$(asdf_data_dir)/shims/${shim_name}" ]; then
printf "%s %s %s\\n" "unknown command:" "${shim_name}." "Perhaps you have to reshim?" >&2 printf "%s %s %s\n" "unknown command:" "${shim_name}." "Perhaps you have to reshim?" >&2
return 1 return 1
fi fi
@ -803,15 +803,15 @@ with_shim_executable() {
done done
if [ -n "${preset_plugin_versions[*]}" ]; then if [ -n "${preset_plugin_versions[*]}" ]; then
printf "%s %s\\n" "No preset version installed for command" "$shim_name" printf "%s %s\n" "No preset version installed for command" "$shim_name"
printf "%s\\n\\n" "Please install a version by running one of the following:" printf "%s\n\n" "Please install a version by running one of the following:"
for preset_plugin_version in "${preset_plugin_versions[@]}"; do for preset_plugin_version in "${preset_plugin_versions[@]}"; do
printf "%s %s\\n" "asdf install" "$preset_plugin_version" printf "%s %s\n" "asdf install" "$preset_plugin_version"
done done
printf "\\n%s %s\\n" "or add one of the following versions in your config file at" "$closest_tool_version" printf "\n%s %s\n" "or add one of the following versions in your config file at" "$closest_tool_version"
else else
printf "%s %s\\n" "No version is set for command" "$shim_name" printf "%s %s\n" "No version is set for command" "$shim_name"
printf "%s %s\\n" "Consider adding one of the following versions in your config file at" "$closest_tool_version" printf "%s %s\n" "Consider adding one of the following versions in your config file at" "$closest_tool_version"
fi fi
shim_plugin_versions "${shim_name}" shim_plugin_versions "${shim_name}"
) >&2 ) >&2

114
scripts/checkstyle.py Executable file
View File

@ -0,0 +1,114 @@
#!/usr/bin/env python3
import re
import sys
import os
import argparse
from pathlib import Path
from typing import List, Dict, Any # compat
# This file checks Bash and Shell scripts for violations not found with
# shellcheck or existing methods. You can use it in several ways:
#
# Lint all .bash, .sh, and .bats files and print out violations
# $ ./scripts/checkstyle.py
#
# The former, but also fix all violations. This must be ran until there
# are zero violations since any line can have more than one violation
# $ ./scripts/checkstyle.py --fix
#
# Lint a particular file
# $ ./scripts/checkstyle.py ./lib/functions/installs.bash
class c:
RED = '\033[91m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
BLUE = '\033[94m'
MAGENTA = '\033[95m'
CYAN = '\033[96m'
RESET = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
# Before: printf '%s\\n' '^w^'
# After: printf '%s\n' '^w^'
def noDoubleBackslashFixer(line: str, rule: Dict[str, str], m: re.Match[str]) -> str:
prestr = line[0:m.start('match')]
midstr = line[m.start('match'):m.end('match')]
poststr = line[m.end('match'):]
fixed_line = f'{prestr}{midstr[1:]}{poststr}'
return fixed_line
def lintfile(filepath: Path, rules: List[Dict[str, str]], options: Dict[str, Any]):
content_arr = filepath.read_text().split('\n')
for line_i, line in enumerate(content_arr):
for rule in rules:
m = re.search(rule['regex'], line)
if m is not None and m.group('match') is not None:
dir = os.path.relpath(filepath.resolve(), Path.cwd())
prestr = line[0:m.start('match')]
midstr = line[m.start('match'):m.end('match')]
poststr = line[m.end('match'):]
print(f'{c.CYAN}{dir}{c.RESET}:{line_i + 1}')
print(f'{c.MAGENTA}{rule["name"]}{c.RESET}: {rule["reason"]}')
print(f'{prestr}{c.RED}{midstr}{c.RESET}{poststr}')
print()
if options['fix']:
content_arr[line_i] = rule['fixer_fn'](line, rule, m)
rule['found'] += 1
if options['fix']:
filepath.write_text('\n'.join(content_arr))
def main():
rules = [
{
'name': 'no-double-backslash',
'regex': '".*?(?P<match>\\\\\\\\[abeEfnrtv\'"?xuUc]).*?(?<!\\\\)"',
'reason': 'Backslashes are only required if followed by a $, `, ", \\, or <newline>',
'fixer_fn': noDoubleBackslashFixer,
'found': 0
},
]
parser = argparse.ArgumentParser()
parser.add_argument('files', metavar='FILES', nargs='*')
parser.add_argument('--fix', action='store_true')
args = parser.parse_args()
options = {
'fix': args.fix
}
# parse files and print matched lints
if len(args.files) > 0:
for file in args.files:
p = Path(file)
if p.is_file():
lintfile(p, rules, options)
else:
for file in Path.cwd().glob('**/*'):
if file.name.endswith('.bash') or file.name.endswith('.sh') or file.name.endswith('.bats'):
if file.is_file():
lintfile(file, rules, options)
# print final results
print(f'{c.UNDERLINE}TOTAL ISSUES{c.RESET}')
for rule in rules:
print(f'{c.MAGENTA}{rule["name"]}{c.RESET}: {rule["found"]}')
grand_total = sum([rule['found'] for rule in rules])
print(f'GRAND TOTAL: {grand_total}')
# exit
if grand_total == 0:
exit(0)
else:
exit(2)
main()