mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2025-10-15 17:38:54 +02:00
feat: TFLint: Add --hook-config=--delegate-chdir to use tflint -chdir (#512)
Co-authored-by: Maksym Vlasov <MaxymVlasov@users.noreply.github.com>
This commit is contained in:
parent
1431664e59
commit
1e9debc02f
12 changed files with 101 additions and 16 deletions
|
|
@ -28,7 +28,7 @@ function main {
|
|||
} || {
|
||||
local exit_code=$?
|
||||
common::colorify "red" "Command 'tflint --init' failed:"
|
||||
echo "${TFLINT_INIT}"
|
||||
echo -e "${TFLINT_INIT}"
|
||||
return ${exit_code}
|
||||
}
|
||||
|
||||
|
|
@ -41,21 +41,30 @@ function main {
|
|||
# Arguments:
|
||||
# dir_path (string) PATH to dir relative to git repo root.
|
||||
# Can be used in error logging
|
||||
# change_dir_in_unique_part (string/false) Modifier which creates
|
||||
# possibilities to use non-common chdir strategies.
|
||||
# Availability depends on hook.
|
||||
# args (array) arguments that configure wrapped tool behavior
|
||||
# Outputs:
|
||||
# If failed - print out hook checks status
|
||||
#######################################################################
|
||||
function per_dir_hook_unique_part {
|
||||
local -r dir_path="$1"
|
||||
shift
|
||||
local -r change_dir_in_unique_part="$2"
|
||||
shift 2
|
||||
local -a -r args=("$@")
|
||||
|
||||
TFLINT_OUTPUT=$(tflint "${args[@]}" 2>&1)
|
||||
if [ "$change_dir_in_unique_part" == "delegate_chdir" ]; then
|
||||
local dir_args="--chdir=$dir_path"
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC2086 # we need to remove the arg if its unset
|
||||
TFLINT_OUTPUT=$(tflint ${dir_args:-} "${args[@]}" 2>&1)
|
||||
local exit_code=$?
|
||||
|
||||
if [ $exit_code -ne 0 ]; then
|
||||
common::colorify "yellow" "TFLint in $dir_path/:"
|
||||
echo "$TFLINT_OUTPUT"
|
||||
echo -e "$TFLINT_OUTPUT"
|
||||
fi
|
||||
|
||||
# return exit code to common::per_dir_hook
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue