我正在为exercism.io 编写练习。我的导师说我的代码应该由一些 go lint 来检查,他建议我尝试 golint 和 golangci-lint。我通过安装 golintgo get -u golang.org/x/lint/golint
并启动它:
rustam:hamming $ golint hamming.go
rustam:hamming $
但它什么也不返回。此外,如果我使用 golangci-lint 也会得到相同的结果——什么都没有。我不知道为什么。
有我的代码,充满了风格错误:
// 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
}
还有我的 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"
和我的 ~/.bash_profile
export GOPATH=$HOME/go
export GOBIN=$HOME/go/bin
export PATH=$PATH:$GOPATH/bin
如果您能指出我的错误,我将不胜感激。