Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxymVlasov committed Oct 5, 2022
1 parent 68a7f51 commit 7866b64
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
16 changes: 6 additions & 10 deletions hooks/_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,17 @@ function common::is_hook_run_on_whole_repo {
# 3. Complete hook execution and return exit code
# Arguments:
# hook_id (string) hook ID, see `- id` for details in .pre-commit-hooks.yaml file
# args_array_length (integer) Count of arguments in args array.
# args (array) arguments that configure wrapped tool behavior
# args (string with array) arguments that configure wrapped tool behavior
# files (array) filenames to check
#######################################################################
function common::per_dir_hook {
local -r hook_id="$1"
local -i args_array_length=$2
shift 2
# Expand args to a true array
local -a args=()
# Expand args to a true array.
# Based on https://stackoverflow.com/a/10953834
while ((args_array_length-- > 0)); do
args+=("$1")
shift
done
while read -r -d '' ARG; do
args+=("$ARG")
done < <(echo "$2" | xargs printf '%s\0')
shift 2
# assign rest of function's positional ARGS into `files` array,
# despite there's only one positional ARG left
local -a -r files=("$@")
Expand Down
2 changes: 1 addition & 1 deletion hooks/tfupdate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function main {
# JFYI: suppress color for `tfupdate` is N/A`

# shellcheck disable=SC2153 # False positive
common::per_dir_hook "$HOOK_ID" "${#ARGS[@]}" "${ARGS[@]}" "${FILES[@]}"
common::per_dir_hook "$HOOK_ID" "${ARGS[*]}" "${FILES[@]}"
}
#######################################################################
# Unique part of `common::per_dir_hook`. The function is executed in loop
Expand Down

0 comments on commit 7866b64

Please sign in to comment.