Skip to content

Releases: dominikh/go-tools

Staticcheck 2024.1rc1 (v0.5.0-rc.1)

01 Jul 20:06
2024.1rc1
Compare
Choose a tag to compare
Pre-release

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.

Backwards incompatible changes

Staticcheck 2024.1 contains the following backwards incompatible changes:

  • The 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.

Improved Go 1.22 support

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.

Added Go 1.23 support

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.

Improved handling of Go versions

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.

Checks

New checks

The following checks have been added:

  • SA1031 flags overlapping destination and source slices passed to certain encoding functions.
  • SA1032 flags calls to errors.Is where the two arguments have been swapped.
  • SA4032 flags impossible comparisons of runtime.GOOS and runtime.GOARCH based on the file’s build tags.
  • SA6006 flags io.WriteString(w, string(b)) as it would be both simpler and more efficient to use w.Write(b).
  • SA9009 flags comments that look like they intend to be compiler directives but which aren’t due to extraneous whitespace.

Changed checks

The following checks have been improved:

  • QF1001 no longer panics on expressions involving β€œkey: value” pairs (issue 1484).
  • S1008 now understands that some built-in functions never return negative values. For example, it now negates len(x) > 0 as len(x) == 0 (issue 1422).
  • S1009 now flags unnecessary nil checks that involve selector expressions (issue 1527).
  • S1017 no longer flags if else branches (issue 1447).
  • SA1006 now detects more Printf-like functions from the standard library (issue 1528).
  • SA1015 now skips any code targeting Go 1.23 or newer (issue 1558).
  • SA1029 now flags uses of the empty struct (struct{}) as context keys (issue 1504).
  • SA4003 now flags pointless integer comparisons that involve literals, not just constants from the math package (issue 1470).
  • SA4015 now supports conversions that involve generics.
  • SA4023 no longer panics on type sets that contain arrays (issue 1397).
  • SA5001 now emits a clearer message (issue 1489).
  • SA9003 has been disabled by default because of too many noisy positives (issue 321).
  • ST1000 now permits punctuation following the package name, as in β€œPackage pkg, which …” (issue 1452).
  • ST1018 now accepts variation selectors in emoji and certain Arabic formatting characters in string literals (issue 1456).
  • ST1020 no longer flags comments that start with a deprecation notice (issue 1378).
  • U1000 handles generic interfaces slightly better, reducing the number of false positives.
  • Due to improvements in the intermediate representation, various checks may now detect more problems.

Miscellaneous changes and fixes

  • The 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.
  • Malformed staticcheck.conf files now cause more useful errors to be emitted.
  • Labeled statements with blank labels no longer cause panics.
  • Functions with named return parameters that never actually return no longer cause panics (issue 1533).

Staticcheck 2023.1.7 (v0.4.7)

22 Feb 13:36
2023.1.7
Compare
Choose a tag to compare

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.

Staticcheck 2023.1.6 (v0.4.6)

13 Sep 10:25
2023.1.6
Compare
Choose a tag to compare

This release fixes the following bugs:

Staticcheck 2023.1.5 (v0.4.5)

17 Aug 16:25
2023.1.5
Compare
Choose a tag to compare

This release fixes the following bug:

  • A crash involving methods named _

Staticcheck 2023.1.4 (v0.4.4)

17 Aug 11:50
2023.1.4
Compare
Choose a tag to compare

This release adds support for Go 1.21 and fixes the following bugs:

  • Three crashes when encountering unnecessarily parenthesized statements (#1393, #1400)
  • Unnecessarily high memory usage when analyzing composite literals such as []int{1<<31: 1} (#1393)
  • A false positive in S1011 when appending to a dynamic left-hand side (#1399)
  • A crash involving generics (#1410)
  • A false positive in SA9001 involving control flow statements (#488)
  • A false positive in ST1003, complaining about the names of fuzz functions (#1420)

Staticcheck 2023.1.3 (v0.4.3)

15 Mar 11:48
2023.1.3
Compare
Choose a tag to compare

This release fixes the following bugs:

  • A crash when embedding type aliases of unnamed types (issue 1361)
  • A false positive in U1000, claiming that type aliases are unused (issue 1365)
  • A bug in the binary formatter that prevented correct merging behavior for some checks (issue 1372)

Staticcheck 2023.1.2 (v0.4.2)

16 Feb 17:37
2023.1.2
Compare
Choose a tag to compare

This release fixes a bug that prevented the binary formatter from working (issue 1370).

Staticcheck 2023.1.1 (v0.4.1)

14 Feb 10:33
2023.1.1
Compare
Choose a tag to compare

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 (v0.4.0)

03 Feb 02:18
2023.1
Compare
Choose a tag to compare

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:

  • The wording of S1001 has been made clearer for cases involving arrays. Furthermore, it no longer suggests using copy when the function has been shadowed.
  • S1011 now recognizes index-based loops (issue 881).
  • SA1019 no longer flags tests (internal or external) that use deprecated API from the package under test (issue 1285). Furthermore, entire declaration groups (such as groups of constants) can now be marked as deprecated (issue 1313).
  • SA4017 now detects more functions, including those in the time package (issue 1353). Additionally, its wording has been made clearer.
  • SA5010 no longer gets confused by type assertions involving generic types (issue 1354).
  • ST1005 no longer flags errors that start with alpha-numeric acronyms such as P384.
  • Improvements to our intermediate representation may allow various checks to find more problems.

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).

Staticcheck 2022.1.3 (v0.3.3)

29 Jul 02:14
v0.3.3
Compare
Choose a tag to compare

This release addresses the following issues:

  • Staticcheck maintains a cache to speed up repeated runs. This cache needs to be pruned regularly to keep its size in check. This is meant to happen automatically, but it hasn’t since Staticcheck 2020.2. This release corrects that (issue 1283.)
  • Some type sets containing both bidirectional and unidirectional channels would lead to panics (issue 1304)