Staticcheck - The advanced Go linter
This release fixes some minor issues in Staticcheck’s intermediate representation. Furthermore, it improves the way QF1003 generates suggested fixes, working around constraints in the language server protocol.
The released binaries for this version have been built with Go 1.22 and should no longer panic when checking code targeting Go 1.22.
This release fixes the following bugs:
This release fixes the following bug:
_
This release adds support for Go 1.21 and fixes the following bugs:
[]int{1<<31: 1}
(#1393)This release fixes the following bugs:
This release fixes a bug that prevented the binary
formatter from working (issue 1370).
This release fixes a crash, a false positive in U1000 (issue 1360) and improves the way deprecated API is flagged (issue 1318).
When targeting a Go version that is older than the version that deprecated an API, SA1019 will no longer flag the use even if there is already an alternative available in the targeted Go version.
For example, math/rand.Seed
has been deprecated in Go 1.20, but an alternative has existed since Go 1.0. In the past, we would flag uses of Seed
even if targeting e.g. Go 1.19, to encourage better forwards compatibility. This can lead to unnecessary churn, however, because the correct change may depend on the Go version in use. For example, for Seed
before Go 1.20, the alternative is to use a separate instance of math/rand.Rand
, whereas in Go 1.20, a possible alternative is to simply drop the call to Seed
.
Staticcheck 2023.1 adds support for Go 1.20, brings minor improvements to various checks, and replaces U1000 with a new implementation.
The following checks have been improved:
Staticcheck now knows about version 2 of the k8s.io/klog package, in particular which functions abort control flow (issue 1307).
In addition to these minor improvements, U1000 has been rewritten from the ground up, operating on a program representation more suited to the task. In practice this means that there will be fewer false positives and more true positives.
Overall, the rewrite fixes at least eight known bugs, both ones that have been a nuisance for a while, as well as ones newly introduced by generics (issue 507, issue 633, issue 810, issue 812, issue 1199, issue 1249, issue 1282, issue 1333).
This release addresses the following issues:
This release addresses the following false positives, crashes, infinite loops, and performance issues:
len
for the builtin (issue 1181)switch
statements if their order is significant due to the use of fallthrough
(issue 1188)_
has been fixed (issue 1268)string | []byte
has been fixed (issue 1270)Additionally it is strongly recommended to use Go 1.18.2 for building Staticcheck, as it fixes further generics-related bugs in the type checker.