Skip to content

Commit

Permalink
Enforce gofmt in TravisCI (#164)
Browse files Browse the repository at this point in the history
Add a script run at build time that checks Go formatting and fails if it
needs formatting.
  • Loading branch information
soulclimberchick committed Aug 20, 2020
1 parent bf9e68d commit 239760a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ before-install:
- nvm use stable
- cd service/ && go get -u -v -d && cd ..
- cd tests/ && npm install && npm install chromedriver geckodriver && cd ..
- gofmt -l .


script:
Expand All @@ -36,8 +37,7 @@ script:
- npm install -g http-server mocha eslint
- eslint view/web/app-jarvis.js
- echo "checking go format ..."
- diff -u <(echo -n) <(gofmt -d ./src ./tsdb)
- echo "perfect go format. moving ahead ..."
- build/scripts/gofmt.sh
- cd view/web/ && npm start && cd ../..
- go test service/controllers/controllers_test.go
- cd tests/
Expand Down
9 changes: 9 additions & 0 deletions build/scripts/gofmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

echo 'running go fmt on all packages...'
invalidFiles=$(gofmt -l . 2>&1)
if [ "$invalidFiles" ]; then
echo "These files did not pass the 'go fmt' check, please run 'go fmt' on them:"
echo $invalidFiles
exit 1
fi
4 changes: 2 additions & 2 deletions service/controllers/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func MessagesController(w http.ResponseWriter, r *http.Request) {

func filterForSpeech(s string) string {

s = strings.Replace(s, "?", " ", -1)
s = strings.Replace(s, "?", " ", -1)
s = strings.Replace(s, "%", " ", -1)
s = strings.Replace(s, "#", " ", -1)
s = strings.Replace(s, "$", " ", -1)
Expand Down Expand Up @@ -404,4 +404,4 @@ func scrapeYahoo(query string) []messageQueryBody {
resultObj = append(resultObj, resultElement)
}
return resultObj
}
}

0 comments on commit 239760a

Please sign in to comment.