Add shfmt to the validate make target

We need to run on a directory since shell files might have no extension.
There are few shell files, so speed should not be an issue.

Fixes #1166.
This commit is contained in:
Daniel Martí 2016-11-17 11:51:24 +00:00
parent cdb66f5421
commit b9d13467b9
3 changed files with 31 additions and 0 deletions

View File

@ -36,6 +36,15 @@ RUN mkdir -p /usr/src/criu \
&& cd /usr/src/criu \
&& make install-criu
# install shfmt
RUN mkdir -p /go/src/github.com/mvdan \
&& cd /go/src/github.com/mvdan \
&& git clone https://github.com/mvdan/sh \
&& cd sh \
&& git checkout -f v0.4.0 \
&& go install ./cmd/shfmt \
&& rm -rf /go/src/github.com/mvdan
# setup a playground for us to spawn containers in
ENV ROOTFS /busybox
RUN mkdir -p ${ROOTFS} \

View File

@ -119,6 +119,7 @@ clean:
validate:
script/validate-gofmt
script/validate-shfmt
go vet ./...
ci: validate localtest

21
script/validate-shfmt Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
badFiles=()
while read f; do
badFiles+=("$f")
done < <(shfmt -l . | grep -v Godeps/)
if [ ${#badFiles[@]} -eq 0 ]; then
echo 'Congratulations! All shell source files are properly formatted.'
else
{
echo "These files are not properly shfmt'd:"
for f in "${badFiles[@]}"; do
echo " - $f"
done
echo
echo 'Please reformat the above files using "shfmt -w" and commit the result.'
echo
} >&2
false
fi