猿问

staticcheck 不希望地检查直接目录之外的项目

staticcheck不希望地扫描直接目录树之外的代码。

如何让 staticcheck 仅扫描直接目录树,并忽略内部内容,例如: /usr/local/go/src/runtime/internal/sys/

我在staticcheck.io上搜索了文档,但没有找到任何关于这种行为的信息。

例子:

$ find . -name "*.go"

./main.go

./exporter/gather.go

./exporter/metrics.go

./exporter/structs.go

./exporter/http.go

./exporter/prometheus.go

./config/config.go

./bitbucket-exporter_test.go

$ staticcheck ./...

/usr/local/go/src/runtime/internal/sys/arch.go:24:7:    other declaration of PtrSize (compile)

/usr/local/go/src/runtime/internal/sys/arch.go:27:7:    other declaration of StackGuardMultiplier (compile)

/usr/local/go/src/runtime/internal/sys/stubs.go:9:7: PtrSize redeclared in this block (compile)

/usr/local/go/src/runtime/internal/sys/stubs.go:10:24: undeclared name: Uintreg (compile)

/usr/local/go/src/runtime/internal/sys/stubs.go:16:7: StackGuardMultiplier redeclared in this block (compile)

$ staticcheck -version

staticcheck 2021.1 (v0.2.0)

$ go version

go version go1.17.4 linux/amd64


拉风的咖菲猫
浏览 245回答 1
1回答

12345678_0001

环境好像有问题。在单独的 Ubuntu 机器上,安装了 go 和 staticcheck,staticcheck 现在按预期运行:$ staticcheck ./...config/config.go:114:6: func getAuth is unused (U1000)exporter/http.go:38:2: should use for range instead of for { select {} } (S1000)exporter/http.go:55:6: func getEarlierDaysMs is unused (U1000)exporter/http.go:70:10: error strings should not be capitalized (ST1005)exporter/http.go:79:10: error strings should not be capitalized (ST1005)exporter/http.go:84:10: error strings should not be capitalized (ST1005)exporter/http.go:84:10: error strings should not end with punctuation or a newline (ST1005)exporter/http.go:88:10: error strings should not be capitalized (ST1005)exporter/http.go:88:10: error strings should not end with punctuation or a newline (ST1005)exporter/http.go:92:10: error strings should not be capitalized (ST1005)exporter/http.go:92:10: error strings should not end with punctuation or a newline (ST1005)exporter/structs.go:101:12: unknown JSON option "int64" (SA5008)$ go versiongo version go1.17.4 linux/amd64$ staticcheck --versionstaticcheck 2021.1.2 (v0.2.2)更多调查显示,最有可能的是,以前的文件版本保持不变的脏升级可能导致 staticcheck 出现此错误。卸载 go 和 staticcheck,确保删除旧的$GOROOT(/usr/local/go在 linux 上),然后重新安装 go 和 staticcheck,解决了问题。
随时随地看视频慕课网APP

相关分类

Go
我要回答