Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

Commit

Permalink
Merge pull request weaveworks#55 from weaveworks/lint-tf
Browse files Browse the repository at this point in the history
Use hclfmt to lint terraform.
  • Loading branch information
tomwilkie authored Dec 9, 2016
2 parents fd875e2 + 05ad5f2 commit 81d80f3
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lint
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ while true; do
done

spell_check() {
filename="$1"
local filename="$1"
local lint_result=0

# we don't want to spell check tar balls, binaries, Makefile and json files
Expand All @@ -66,8 +66,8 @@ spell_check() {
}

test_mismatch() {
filename="$1"
package=$(grep '^package ' "$filename" | awk '{print $2}')
local filename="$1"
local package=$(grep '^package ' "$filename" | awk '{print $2}')
local lint_result=0

if [[ $package == "main" ]]; then
Expand All @@ -90,7 +90,7 @@ test_mismatch() {
}

lint_go() {
filename="$1"
local filename="$1"
local lint_result=0

if [ -n "$(gofmt -s -l "${filename}")" ]; then
Expand Down Expand Up @@ -128,10 +128,10 @@ lint_go() {
}

lint_sh() {
filename="$1"
local filename="$1"
local lint_result=0

if [ -n "$(diff <(shfmt -i 4 "${filename}") "${filename}")" ]; then
if ! diff <(shfmt -i 4 "${filename}") "${filename}" >/dev/null; then
lint_result=1
echo "${filename}: run shfmt -i 4 -w ${filename}"
fi
Expand All @@ -145,6 +145,18 @@ lint_sh() {
return $lint_result
}

lint_tf() {
local filename="$1"
local lint_result=0

if ! diff <(hclfmt "${filename}") "${filename}" >/dev/null; then
lint_result=1
echo "${filename}: run hclfmt -w ${filename}"
fi

return $lint_result
}

lint() {
filename="$1"
ext="${filename##*\.}"
Expand All @@ -168,6 +180,7 @@ lint() {
case "$ext" in
go) lint_go "${filename}" || lint_result=1 ;;
sh) lint_sh "${filename}" || lint_result=1 ;;
tf) lint_tf "${filename}" || lint_result=1 ;;
esac

if [ -z "$IGNORE_TEST_PACKAGES" ]; then
Expand Down

0 comments on commit 81d80f3

Please sign in to comment.