chore: add goimports to ci checks

pull/20649/head
Sam Arnold 2021-01-29 11:18:38 -05:00
parent b2f0d05ecc
commit b0d26fe412
4 changed files with 7 additions and 7 deletions

View File

@ -1,8 +1,8 @@
#!/usr/bin/env bash
fmtcount=`git ls-files | grep '.go$' | xargs gofmt -l 2>&1 | wc -l`
fmtcount=`git ls-files | grep '.go$' | xargs goimports -l 2>&1 | wc -l`
if [ $fmtcount -gt 0 ]; then
echo "Some files aren't formatted, please run 'go fmt ./...' to format your source code before committing"
echo "Some files aren't formatted, please run 'goimports -w ./' to format your source code before committing"
exit 1
fi

View File

@ -2,7 +2,7 @@ _This document is currently in draft form._
# Background
The goal of this guide is to capture some Do and Don'ts of Go code for the InfluxDB database. When it comes to Go, writing good code is often achieved with the help of tools like `go fmt` and `go vet`. However there are still some practices not enforceable by any tools. This guide lists some specific practices to follow when writing code for the database.
The goal of this guide is to capture some Do and Don'ts of Go code for the InfluxDB database. When it comes to Go, writing good code is often achieved with the help of tools like `goimports` and `go vet`. However there are still some practices not enforceable by any tools. This guide lists some specific practices to follow when writing code for the database.
*Like everything, one needs to use good judgment.* There will always be times when it doesn't make sense to follow a guideline outlined in this document. If that case arises, be ready to justify your choices.

View File

@ -224,7 +224,7 @@ In case the commit is rejected because it's not formatted you can run
the following to format the code:
```
go fmt ./...
goimports -w ./
go vet ./...
```

View File

@ -184,10 +184,10 @@ def run_tests(race, parallel, timeout, no_vet, junit=False):
logging.info("Fetching module dependencies...")
run("go mod download")
logging.info("Ensuring code is properly formatted with go fmt...")
out = run("go fmt ./...")
logging.info("Ensuring code is properly formatted with goimports ...")
out = run("go run golang.org/x/tools/cmd/goimports -l ./")
if len(out) > 0:
logging.error("Code not formatted. Please use 'go fmt ./...' to fix formatting errors.")
logging.error("Code not formatted. Please use 'goimports -w ./' to fix formatting errors.")
logging.error("{}".format(out))
return False
if not no_vet: