From bf9e68d5650db0f7e83bb462026ac3a68465f244 Mon Sep 17 00:00:00 2001 From: Kira Helm Date: Wed, 19 Aug 2020 15:49:08 -0700 Subject: [PATCH 1/2] Run gofmt to clean up formatting (#164) --- .travis.yml | 2 +- service/controllers/controllers.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 56bc01a..b29b156 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,4 +42,4 @@ script: - go test service/controllers/controllers_test.go - cd tests/ - npm install - - xvfb-run -s "-screen 0 1920x1080x16" -a mocha test.js \ No newline at end of file + - xvfb-run -s "-screen 0 1920x1080x16" -a mocha test.js diff --git a/service/controllers/controllers.go b/service/controllers/controllers.go index 9aefd4a..f04092f 100644 --- a/service/controllers/controllers.go +++ b/service/controllers/controllers.go @@ -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
    .")) } list := listArray.Eq(0) From 239760abeb72050b62dc5e9c62c2495eaa390666 Mon Sep 17 00:00:00 2001 From: Kira Helm Date: Sat, 15 Aug 2020 21:16:49 -0700 Subject: [PATCH 2/2] Enforce gofmt in TravisCI (#164) Add a script run at build time that checks Go formatting and fails if it needs formatting. --- .travis.yml | 4 ++-- build/scripts/gofmt.sh | 9 +++++++++ service/controllers/controllers.go | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100755 build/scripts/gofmt.sh diff --git a/.travis.yml b/.travis.yml index b29b156..815a773 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: @@ -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/ diff --git a/build/scripts/gofmt.sh b/build/scripts/gofmt.sh new file mode 100755 index 0000000..8aae7bf --- /dev/null +++ b/build/scripts/gofmt.sh @@ -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 diff --git a/service/controllers/controllers.go b/service/controllers/controllers.go index f04092f..e4c85a6 100644 --- a/service/controllers/controllers.go +++ b/service/controllers/controllers.go @@ -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) @@ -404,4 +404,4 @@ func scrapeYahoo(query string) []messageQueryBody { resultObj = append(resultObj, resultElement) } return resultObj -} \ No newline at end of file +}