Staticcheck 2022.1 release notes


This release adds support for Go 1.18 and type parameters (generics).

Furthermore, it adds two new flags for handling build tags, -matrix and -merge. Their use is extensively documented on the new Build tags page. Their intended use is for avoiding false positives when dealing with different build tags.

Not tied directly to this release, but worth mentioning regardless: Staticcheck has an official GitHub Action now, which may simplify your CI pipeline.

Minor changes include slightly nicer output from staticcheck -explain, better error messages, and allowing whitespace in flags like -checks.


New checks

The following new checks have been added:

  • SA4028 flags x % 1, which always yields zero, and is sometimes accidentally used instead of x % 2
  • SA4029 flags misuses of sort.IntSlice and related types
  • SA4030 flags misuses of math/rand that always generate zeros
  • SA4031 flags comparisons of never-nil values against nil
  • SA9007 flags attempts at deleting system directories
  • SA9008 flags accidental shadowing in the else branches of type assertions

Changed checks

The following checks have been improved:

  • S1001 now simplifies more loops
  • S1038 now simplifies formatted printing in log and testing, in addition to fmt
  • SA1019 no longer flags deprecated API in the Go standard library if it doesn’t know when the API was deprecated. This is to avoid false positives when using older versions of Staticcheck on newer versions of Go, in particular Go’s master branch.
  • SA1020 no longer flags net/http.ListenAndServe with a completely empty address
  • ST1001 various packages of have been whitelisted by default
  • ST1008 no longer flags functions that return (..., error, bool)
  • ST1018 no longer flags emoji sequences
  • ST1023 no longer makes erroneous suggestions
  • Numerous checks have a better understanding of integer literals and can detect mistakes involving unconventional literals such as ---1 instead of -1
  • Some runtime crashes have been fixed

Staticcheck 2022.1.1 release notes

This release addresses the following false positives, crashes, and infinite loops:

Staticcheck 2022.1.2 release notes

This release addresses the following false positives, crashes, infinite loops, and performance issues:

  • For certain packages that contain tens of thousands of types and methods, such as those generated by ygot, Staticcheck now finishes much faster.
  • Several infinite loops when handling recursive type parameters have been fixed
  • S1009 no longer mistakes user-defined functions named len for the builtin (issue 1181)
  • ST1015 no longer reorders switch statements if their order is significant due to the use of fallthrough (issue 1188)
  • SA1013 now detects constants more robustly, avoiding both false negatives and false positives. Furthermore, it makes sure that offending methods implement io.Seeker and doesn’t just rely on the name Seek (issue 1213).
  • SA5008 now understands more third-party extensions to json struct tags
  • A crash involving functions named _ has been fixed (issue 1268)
  • A crash involving slicing type parameters of type string | []byte has been fixed (issue 1270)
  • SA1019 now handles imports of deprecated standard library packages in the same way it handles other deprecated API, taking the targeted Go version into consideration (issue 1117)

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.

Staticcheck 2022.1.3 release notes

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)