Skip to content

Commit b9d1346

Browse files
committed
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.
1 parent cdb66f5 commit b9d1346

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ RUN mkdir -p /usr/src/criu \
3636
&& cd /usr/src/criu \
3737
&& make install-criu
3838

39+
# install shfmt
40+
RUN mkdir -p /go/src/github.com/mvdan \
41+
&& cd /go/src/github.com/mvdan \
42+
&& git clone https://github.com/mvdan/sh \
43+
&& cd sh \
44+
&& git checkout -f v0.4.0 \
45+
&& go install ./cmd/shfmt \
46+
&& rm -rf /go/src/github.com/mvdan
47+
3948
# setup a playground for us to spawn containers in
4049
ENV ROOTFS /busybox
4150
RUN mkdir -p ${ROOTFS} \

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ clean:
119119

120120
validate:
121121
script/validate-gofmt
122+
script/validate-shfmt
122123
go vet ./...
123124

124125
ci: validate localtest

script/validate-shfmt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
badFiles=()
4+
while read f; do
5+
badFiles+=("$f")
6+
done < <(shfmt -l . | grep -v Godeps/)
7+
8+
if [ ${#badFiles[@]} -eq 0 ]; then
9+
echo 'Congratulations! All shell source files are properly formatted.'
10+
else
11+
{
12+
echo "These files are not properly shfmt'd:"
13+
for f in "${badFiles[@]}"; do
14+
echo " - $f"
15+
done
16+
echo
17+
echo 'Please reformat the above files using "shfmt -w" and commit the result.'
18+
echo
19+
} >&2
20+
false
21+
fi

0 commit comments

Comments
 (0)