I'm coding exercise for exercism.io. And my mentor said that my code should be checked by some go linters, and he suggested me to try golint and golangci-lint.
I installed golint via go get -u golang.org/x/lint/golint, and started it:
rustam:hamming $ golint hamming.go
rustam:hamming $
but it returns nothing. Also if I use golangci-lint there is same result — just nothing. And I have no idea why.
There is my code, full of style mistakes:
// Package hamming is Exercism.io exercise
package hamming
import "errors"
// Distance — Calculating Hamming Distance for two DNA strands
func Distance(a, b string) (int, error) {
if len(a) != len(b) {
return 0, errors.New("Strands should be equal size")
}
if len(a) == 0 || len(b) == 0 {
return 0, nil
}
var hd int = 0
for i := 0; i < len(a); i++ {
if a[i] != b[i] {
hd++
}
}
return hd, nil
}
And there is my go env:
rustam:hamming $ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/rustam/go/bin"
GOCACHE="/Users/rustam/Library/Caches/go-build"
GOENV="/Users/rustam/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/rustam/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4j/4rjv22zs1pb68wssv5gn2wfw0000gn/T/go-build148685464=/tmp/go-build -gno-record-gcc-switches -fno-common"
and my ~/.bash_profile
export GOPATH=$HOME/go
export GOBIN=$HOME/go/bin
export PATH=$PATH:$GOPATH/bin
I'd appreciate it if you could point out my mistakes.
In Go, the minimal checks might be the Go tools,
go fmt,go vet, andgolint.Here is a minimum, reproducible example (see How to create a Minimal, Reproducible Example) that shows that your
hamming.goprogram passes all current checks.Command golint
Your mentor is using an old, obsolete version of
golint. For the current version, they should runHas your mentor explained the limited purpose of
golint? For example, "Golint is not perfect, and has both false positives and false negatives. Do not treat its output as a gold standard."Here is my attempt at a solution: