0

我正在针对一个文件运行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
}

该命令在 Docker 容器中以golang:alpine用户身份启动root

4

1 回答 1

0

我在 Github 上发现了类似的问题:https ://github.com/alectomas/gometalinter/issues/149

来自评论https://github.com/alectomas/gometalinter/issues/149#issuecomment-371928626的解决方案对我有用:

env CGO_ENABLED=0 gometalinter ./src/main.go
于 2018-10-04T12:28:39.797 回答