To ensure good code quality, we are looking this week at some golang (one of the language used for many of our project at C4DT) helping us to do so. Some idea where taken from the Awesome Go List, a good reference for everything related to golang.
First, we show some “classic” golang tools used
- gofmt: check that formatting follow the golang standard
- the -s flag is quite nice also, as it simplify code thus helping to write concise code
- go vet: static code analyzer, check for useless assignment, unreachable code and some other standard mistakes
- golint: like gofmt but different, the latter can rewrite the files as needed but the differences shown by golint usually can’t be made automatically
And now, the newcomers
- staticcheck: the (most?) powerful golang static analyzer out there
- the only one actually checking for Deprecated fields
- simplify/idiomaticise code
- has a well documented list of rules, always know why it ask for changes
- go-mod-outdated: check for outdated dependencies
- you might want to run it with -direct -update to only have to direct and updatable
- avoid much of the hassle of keeping go.{mod,sum} up to date
Of course, all these can easily be added to a Continuous Integration system, failing the build if any show an errors.