Skip to content

Commit 7866b64

Browse files
committed
Apply review suggestions
1 parent 68a7f51 commit 7866b64

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

hooks/_common.sh

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,21 +164,17 @@ function common::is_hook_run_on_whole_repo {
164164
# 3. Complete hook execution and return exit code
165165
# Arguments:
166166
# hook_id (string) hook ID, see `- id` for details in .pre-commit-hooks.yaml file
167-
# args_array_length (integer) Count of arguments in args array.
168-
# args (array) arguments that configure wrapped tool behavior
167+
# args (string with array) arguments that configure wrapped tool behavior
169168
# files (array) filenames to check
170169
#######################################################################
171170
function common::per_dir_hook {
172171
local -r hook_id="$1"
173-
local -i args_array_length=$2
174-
shift 2
172+
# Expand args to a true array
175173
local -a args=()
176-
# Expand args to a true array.
177-
# Based on https://stackoverflow.com/a/10953834
178-
while ((args_array_length-- > 0)); do
179-
args+=("$1")
180-
shift
181-
done
174+
while read -r -d '' ARG; do
175+
args+=("$ARG")
176+
done < <(echo "$2" | xargs printf '%s\0')
177+
shift 2
182178
# assign rest of function's positional ARGS into `files` array,
183179
# despite there's only one positional ARG left
184180
local -a -r files=("$@")

hooks/tfupdate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function main {
1515
# JFYI: suppress color for `tfupdate` is N/A`
1616

1717
# shellcheck disable=SC2153 # False positive
18-
common::per_dir_hook "$HOOK_ID" "${#ARGS[@]}" "${ARGS[@]}" "${FILES[@]}"
18+
common::per_dir_hook "$HOOK_ID" "${ARGS[*]}" "${FILES[@]}"
1919
}
2020
#######################################################################
2121
# Unique part of `common::per_dir_hook`. The function is executed in loop

0 commit comments

Comments
 (0)