gofmt
is the automated code format style guide for Go.
Effective Go describes other standard elements of Go style we follow.
All developers should run gofmt
in a pre-commit hook to ensure standard formatting.
gofmt
should be run as a part of every build to enforce the common standard.
go vet
is a static analysis tool that checks for common go errors, such as incorrect use of range loop variables or misaligned printf arguments. CSE Go code should be able to build with no go vet
errors.
golint
can be an effetive tool for finding many issues, but it errors on the side of false positives. It is best used by developers when working on code, not as part of an automated build process.
golangci-lint
is the replacement for the now depricated gometalinter
. It is 2-7x faster than gometalinter
along with a host of other benefits.
One awesome feature of golangci-lint
is that is can be easily introduced to an existing large codebase using the --new-from-rev COMMITID
. With this setting only newly introduced issues are flagged, allowing a team to improve new code without having to fix all historic issues in a large codebase. This provides a great path to improving code-reviews on existing solutions.
The Go language team maintains a list of common Code Review Comments for go that form the basis for a solid checklist for a team working in Go.
- Does this code handle errors correctly? This includes not throwing away errors with
_
assignments and returning errors, instead of in-band error values? - Does this code follow Go standards for method receiver types?
- Does this code pass values when it should?
- Are interfaces in this code defined in the correct packages?
- Do goroutines in this code have clear lifetimes?
- Is parallelism in this code handled via goroutines and channels with synchronous methods?
- Does this code have meaningful Doc Comments?
- Does this code have meaningful Package Comments?
- Does this code use Contexts correctly?
- Do unit tests fail with meaningful messages?