staticcheck undesirably checks items outside the immediate directory

1.1k views Asked by At

staticcheck undesirably scans code outside the immediate directory tree.

How do I get staticcheck to only scan the immediate directory tree, and to ignore internal stuff like: /usr/local/go/src/runtime/internal/sys/?

I searched the documentation at staticcheck.io but did not find anything about this sort of behaviour.

Example:

$ 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

Many thanks.

1

There are 1 answers

0
mikequentel On BEST ANSWER

Thanks @JimB for the clues. There appears to be an issue with the environment. On a separate Ubuntu machine, installed go and staticcheck, and staticcheck now behaves as expected:

$ 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 version
go version go1.17.4 linux/amd64
$ staticcheck --version
staticcheck 2021.1.2 (v0.2.2)

More investigation revealed that most likely, a dirty upgrade, where previous file versions were left untouched, might have caused this error for staticcheck. Uninstalling go and staticcheck, making sure to delete the old $GOROOT (/usr/local/go on linux), then reinstalling go and staticcheck, resolved the problem.