Bot releases are visible (Hide)
Staticcheck 2024.1 contains the following backwards incompatible changes:
keyify
utility has been removed. The recommended alternative is gopls.staticcheck -merge
now exits with a non-zero status if any problems have been found.This release updates Staticcheck’s database of deprecated standard library APIs to cover the Go 1.22 release. Furthermore, checks have been updated to correctly handle the new “for” loop variable scoping behavior as well as ranging over integers.
Staticcheck 2024.1 has full support for iterators / range-over-func. Furthermore, SA1015 will skip any code targeting Go 1.23 or newer, as it is now possible to use time.Tick
without leaking memory.
Go 1.21 more rigorously defined the meaning of the go
directive in go.mod
files, as well as its interactions with //go:build go1.N
build constraints. The go directive now specifies a minimum Go version for the module. Furthermore, it sets the language version that is in effect, which may change the semantics of Go code. For example, before Go 1.22, loop variables were reused across iterations, but since Go 1.22, loop variables only exist for the duration of an iteration. Modules that specify go 1.22
will use the new semantics, while modules that specify an older version will not.
Individual files can both upgrade and downgrade their language version by using //go:build go1.N
directives. In a module that requires Go 1.22, a file specifying Go 1.21 will experience the old loop variable semantics, and vice versa. Because the Go module as a whole still specifies a minimum version, even files specifying an older version will have access to the standard library of the minimum version.
Staticcheck 2024.1 takes all of this into consideration when analyzing the behavior of Go code, when determining which checks are applicable, and when making suggestions. Older versions of Staticcheck were already aware of Go versions, but 2024.1 works on a more fine-grained, per-file basis, and differentiates between the pre- and post-1.21 semantics of the go directive.
The -go
command line flag continues to exist. It will override any module-based version selection. This is primarily useful for Go modules that target older Go versions (because here, the go directive didn’t specify a minimum version), or when working outside of Go modules.
To prevent misinterpreting code, Staticcheck now refuses to analyze modules that require a version of Go that is newer than that with which Staticcheck was built.
The following checks have been added:
errors.Is
where the two arguments have been swapped.io.WriteString(w, string(b))
as it would be both simpler and more efficient to use w.Write(b)
.The following checks have been improved:
len(x) > 0
as len(x) == 0
(issue 1422).if else
branches (issue 1447).struct{}
) as context keys (issue 1504).math
package (issue 1470).keyify
utility has been deleted. This functionality is provided by gopls nowadays.staticcheck -merge
now exits with a non-zero exit status if any problems were found. This matches the behavior of non-merge uses.staticcheck.conf
files now cause more useful errors to be emitted.Published by dominikh 4 months ago
This is a release candidate of Staticcheck 2024.1. It has been built with Go 1.23rc1 and supports analyzing Go 1.23 code, including range-over-func iterators.
Staticcheck 2024.1 contains the following backwards incompatible changes:
keyify
utility has been removed. The recommended alternative is gopls.staticcheck -merge
now exits with a non-zero status if any problems have been found.This release updates Staticcheck’s database of deprecated standard library APIs to cover the Go 1.22 release. Furthermore, checks have been updated to correctly handle the new “for” loop variable scoping behavior as well as ranging over integers.
Staticcheck 2024.1 has full support for iterators / range-over-func. Furthermore, SA1015 will skip any code targeting Go 1.23 or newer, as it is now possible to use time.Tick
without leaking memory.
Go 1.21 more rigorously defined the meaning of the go
directive in go.mod
files, as well as its interactions with //go:build go1.N
build constraints. The go directive now specifies a minimum Go version for the module. Furthermore, it sets the language version that is in effect, which may change the semantics of Go code. For example, before Go 1.22, loop variables were reused across iterations, but since Go 1.22, loop variables only exist for the duration of an iteration. Modules that specify go 1.22
will use the new semantics, while modules that specify an older version will not.
Individual files can both upgrade and downgrade their language version by using //go:build go1.N
directives. In a module that requires Go 1.22, a file specifying Go 1.21 will experience the old loop variable semantics, and vice versa. Because the Go module as a whole still specifies a minimum version, even files specifying an older version will have access to the standard library of the minimum version.
Staticcheck 2024.1 takes all of this into consideration when analyzing the behavior of Go code, when determining which checks are applicable, and when making suggestions. Older versions of Staticcheck were already aware of Go versions, but 2024.1 works on a more fine-grained, per-file basis, and differentiates between the pre- and post-1.21 semantics of the go directive.
The -go
command line flag continues to exist. It will override any module-based version selection. This is primarily useful for Go modules that target older Go versions (because here, the go directive didn’t specify a minimum version), or when working outside of Go modules.
To prevent misinterpreting code, Staticcheck now refuses to analyze modules that require a version of Go that is newer than that with which Staticcheck was built.
The following checks have been added:
errors.Is
where the two arguments have been swapped.io.WriteString(w, string(b))
as it would be both simpler and more efficient to use w.Write(b)
.The following checks have been improved:
len(x) > 0
as len(x) == 0
(issue 1422).if else
branches (issue 1447).struct{}
) as context keys (issue 1504).math
package (issue 1470).keyify
utility has been deleted. This functionality is provided by gopls nowadays.staticcheck -merge
now exits with a non-zero exit status if any problems were found. This matches the behavior of non-merge uses.staticcheck.conf
files now cause more useful errors to be emitted.Published by dominikh 8 months ago
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.
Published by dominikh about 1 year ago
This release fixes the following bugs:
Published by dominikh about 1 year ago
This release fixes the following bug:
_
Published by dominikh about 1 year ago
This release adds support for Go 1.21 and fixes the following bugs:
[]int{1<<31: 1}
(#1393)Published by dominikh over 1 year ago
This release fixes the following bugs:
Published by dominikh over 1 year ago
This release fixes a bug that prevented the binary
formatter from working (issue 1370).
Published by dominikh over 1 year ago
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
.
Published by dominikh over 1 year ago
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).
Published by dominikh about 2 years ago
This release addresses the following issues:
Published by dominikh over 2 years ago
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.
Published by dominikh over 2 years ago
This release addresses the following false positives, crashes, and infinite loops:
Published by dominikh over 2 years ago
Staticcheck 2022.1 adds support for Go 1.18 and generics, adds and tweaks some checks, and introduces the new -matrix
and -merge
flags.
Read the full release notes at https://staticcheck.io/changes/2022.1
Published by dominikh almost 3 years ago
This release fixes some false positives and crashes.
Read the full release notes at https://staticcheck.io/changes/2021.1/#2021.1.2
Published by dominikh about 3 years ago
This release adds support for new language features in Go 1.17, namely conversions from slices to array pointers, the unsafe.Add function, and the unsafe.Slice function.
Additionally, it fixes some false positives.
Read the full release notes at https://staticcheck.io/changes/2021.1#2021.1.1
Published by dominikh over 3 years ago
Read the full release notes at https://staticcheck.io/changes/2021.1
Published by dominikh over 3 years ago
This release fixes a crash and some false positives.
Read the full release notes at https://staticcheck.io/changes/2020.2#2020.2.4
Published by dominikh over 3 years ago
This release fixes a false positive in U1000. See #942 for details.
Published by dominikh over 3 years ago
This release fixes a rare crash in Staticcheck, reduces the number of false positives, and adds support for Go 1.16's io/fs.FileMode
type.
Read the full release notes at https://staticcheck.io/changes/2020.2#2020.2.2