Skip to content

Commit d31cb69

Browse files
authored
fix: Improve tflint --init command execution (antonbabenko#361)
1 parent 896cbff commit d31cb69

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

hooks/terraform_tflint.sh

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ function main {
1717
# shellcheck disable=SC2178 # It's the simplest syntax for that case
1818
ARGS=${ARGS[*]/__GIT_WORKING_DIR__/$(pwd)\/}
1919
# shellcheck disable=SC2128 # It's the simplest syntax for that case
20+
21+
# Run `tflint --init` for check that plugins installed.
22+
# It should run once on whole repo.
23+
{
24+
TFLINT_INIT=$(tflint --init 2>&1) 2> /dev/null &&
25+
common::colorify "green" "Command 'tflint --init' successfully done:" &&
26+
echo -e "${TFLINT_INIT}\n\n\n"
27+
} || {
28+
local exit_code=$?
29+
common::colorify "red" "Command 'tflint --init' failed:"
30+
echo "${TFLINT_INIT}"
31+
return ${exit_code}
32+
}
33+
2034
common::per_dir_hook "$ARGS" "$HOOK_ID" "${FILES[@]}"
2135
}
2236

@@ -34,13 +48,6 @@ function per_dir_hook_unique_part {
3448
local -r args="$1"
3549
local -r dir_path="$2"
3650

37-
# shellcheck disable=SC2091,SC2068 # Suppress error output
38-
TFLINT_INIT=$(tflint --init 2>&1) 2> /dev/null || {
39-
local exit_code=$?
40-
common:colorify "yellow" "tflint init:"
41-
echo "${TFLINT_INIT}"
42-
return ${exit_code}
43-
}
4451
# Print checked PATH **only** if TFLint have any messages
4552
# shellcheck disable=SC2091,SC2068 # Suppress error output
4653
$(tflint ${args[@]} 2>&1) 2> /dev/null || {

0 commit comments

Comments
 (0)