Skip to content

Commit

Permalink
Merge pull request #219 from soulclimberchick/164-add-gofmt-travisci
Browse files Browse the repository at this point in the history
Add gofmt script to enforce Go formatting
  • Loading branch information
Harkishen-Singh authored Aug 20, 2020
2 parents c1b0056 + 239760a commit 03cd6b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 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,10 +37,9 @@ 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/
- npm install
- xvfb-run -s "-screen 0 1920x1080x16" -a mocha test.js
- xvfb-run -s "-screen 0 1920x1080x16" -a mocha test.js
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
6 changes: 3 additions & 3 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 @@ -367,7 +367,7 @@ func scrapeYahoo(query string) []messageQueryBody {
}
var resultObj []messageQueryBody
listArray := doc.Find("div#web > ol")
if len(listArray.Nodes) <= 0{
if len(listArray.Nodes) <= 0 {
logger.Error(errors.New("Unable to find <ol>."))
}
list := listArray.Eq(0)
Expand Down Expand Up @@ -404,4 +404,4 @@ func scrapeYahoo(query string) []messageQueryBody {
resultObj = append(resultObj, resultElement)
}
return resultObj
}
}

0 comments on commit 03cd6b4

Please sign in to comment.