Skip to content

Commit

Permalink
Fix terrafrom_tflint ERROR output for files located in repo root
Browse files Browse the repository at this point in the history
If use constructions like:

```bash
HAVE_ERR="$(tflint "${ARGS[@]}" 2>&1)"
if [ ! -z "$HAVE_ERR" ]; then
  echo >&2 -e "\033[1;31m\nERROR in $path_uniq/:\033[0m"
  tflint "${ARGS[@]}"
fi
```

some errors will not printed.

So this one-liner fits our requirements in the best way.

Fixes #240
  • Loading branch information
MaxymVlasov committed Oct 14, 2021
1 parent 71f7c34 commit 59241c8
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions terraform_tflint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,12 @@ tflint_() {

for path_uniq in $(echo "${paths[*]}" | tr ' ' '\n' | sort -u); do
path_uniq="${path_uniq//__REPLACED__SPACE__/ }"

pushd "$path_uniq" > /dev/null
TFLINT_MSG=$(
tflint "${ARGS[@]}" 2>&1 ||
echo >&2 -e "\033[1;31m\nERROR in ./$path_uniq/:\033[0m" &&
tflint "${ARGS[@]}" # Print TFLint error with PATH
)

# Print checked PATH if TFLint have any messages
if [ ! -z "$TFLINT_MSG" ]; then
echo -e "\n./$path_uniq/:"
echo "$TFLINT_MSG"
fi
# Print checked PATH **only** if TFLint have any messages
# shellcheck disable=SC2091 # Suppress error output
$(tflint "${ARGS[@]}" 2>&1) ||
echo >&2 -e "\033[1;31m\nERROR in $path_uniq/:\033[0m" && tflint "${ARGS[@]}"

popd > /dev/null
done
Expand Down

0 comments on commit 59241c8

Please sign in to comment.