我针对一个文件运行gometalinter:gometalinter ./src/main.go
但会显示golang源文件错误:
90cc5ff9b2ea:/repo# gometalinter ./src/main.go
../usr/local/go/src/net/lookup_unix.go:80:24:warning: unused struct field undeclared name: cgoLookupHost (structcheck)
../usr/local/go/src/net/lookup_unix.go:323:23:warning: undeclared name: cgoLookupPTR (interfacer)
../usr/local/go/src/net/lookup_unix.go:323:23:warning: error return value not checked (undeclared name: cgoLookupPTR) (errcheck)
../usr/local/go/src/net/lookup_unix.go:95:24:warning: error return value not checked (undeclared name: cgoLookupIP) (errcheck)
../usr/local/go/src/net/lookup_unix.go:80:24:warning: error return value not checked (undeclared name: cgoLookupHost) (errcheck)
../usr/local/go/src/net/lookup_unix.go:123:24:warning: unused struct field undeclared name: cgoLookupCNAME (structcheck)
../usr/local/go/src/net/lookup_unix.go:323:23:warning: unused variable or constant undeclared name: cgoLookupPTR (varcheck)
../usr/local/go/src/net/lookup_unix.go:80:24:warning: unused variable or constant undeclared name: cgoLookupHost (varcheck)
../usr/local/go/src/net/lookup_unix.go:95:24:warning: undeclared name: cgoLookupIP (interfacer)
../usr/local/go/src/net/lookup_unix.go:80:24:warning: undeclared name: cgoLookupHost (interfacer)
../usr/local/go/src/net/lookup_unix.go:95:24:warning: unused variable or constant undeclared name: cgoLookupIP (varcheck)
../usr/local/go/src/net/lookup_unix.go:107:23:warning: error return value not checked (undeclared name: cgoLookupPort) (errcheck)
../usr/local/go/src/net/lookup_unix.go:323:23:warning: unused struct field undeclared name: cgoLookupPTR (structcheck)
../usr/local/go/src/net/lookup_unix.go:107:23:warning: unused struct field undeclared name: cgoLookupPort (structcheck)
../usr/local/go/src/net/lookup_unix.go:123:24:warning: unused variable or constant undeclared name: cgoLookupCNAME (varcheck)
../usr/local/go/src/net/lookup_unix.go:123:24:warning: undeclared name: cgoLookupCNAME (interfacer)
../usr/local/go/src/net/lookup_unix.go:123:24:warning: error return value not checked (undeclared name: cgoLookupCNAME) (errcheck)
../usr/local/go/src/net/lookup_unix.go:95:24:warning: unused struct field undeclared name: cgoLookupIP (structcheck)
../usr/local/go/src/net/lookup_unix.go:107:23:warning: unused variable or constant undeclared name: cgoLookupPort (varcheck)
../usr/local/go/src/net/lookup_unix.go:107:23:warning: undeclared name: cgoLookupPort (interfacer)
如何只对一个文件运行
gometalinter
或仅对./src
目录运行?我的配置:
{
"Deadline": "5m",
"EnableGC": true,
"Enable": [
"deadcode",
"gocyclo",
"gofmt",
"gotype",
"goimports",
"golint",
"gosimple",
"ineffassign",
"interfacer",
"misspell",
"unconvert",
"unused",
"vet",
"varcheck",
"maligned",
"errcheck",
"megacheck",
"goconst",
"structcheck"
],
"Cyclo": 10,
"Aggregate": true
}
该命令是基于
golang:alpine
用户在基于root
的Docker容器中启动的。 最佳答案
我在Github上发现了类似的问题:https://github.com/alecthomas/gometalinter/issues/149
评论https://github.com/alecthomas/gometalinter/issues/149#issuecomment-371928626的解决方案对我有效:
env CGO_ENABLED=0 gometalinter ./src/main.go
关于go - gometalinter正在检查/usr/local/go文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52642294/