Debian Codegraph @

website/content/changes/2022.1.md

raw
1 ---
2 title: Staticcheck 2022.1 release notes
3 linkTitle: "2022.1 (v0.3.0)"
4 weight: -7
5 ---
6
7 ## Improvements {#improvements}
8
9 This release adds support for Go 1.18 and type parameters (generics).
10
11 Furthermore, it adds two new flags for handling build tags, `-matrix` and `-merge`. Their use is extensively documented
12 on the new [Build tags]({{< relref "/docs/running-staticcheck/cli/build-tags" >}}) page. Their intended use is for
13 avoiding false positives when dealing with different build tags.
14
15 Not tied directly to this release, but worth mentioning regardless: Staticcheck has an [official GitHub
16 Action](https://github.com/dominikh/staticcheck-action) now, which may simplify your CI pipeline.
17
18 Minor changes include slightly nicer output from `staticcheck -explain`, better error messages, and allowing whitespace in flags like `-checks`.
19
20 ## Checks {#checks}
21
22 ### New checks {#checks-new}
23
24 The following new checks have been added:
25
26 - {{< check "SA4028" >}} flags `x % 1`, which always yields zero, and is sometimes accidentally used instead of `x % 2`
27 - {{< check "SA4029" >}} flags misuses of `sort.IntSlice` and related types
28 - {{< check "SA4030" >}} flags misuses of `math/rand` that always generate zeros
29 - {{< check "SA4031" >}} flags comparisons of never-nil values against nil
30 - {{< check "SA9007" >}} flags attempts at deleting system directories
31 - {{< check "SA9008" >}} flags accidental shadowing in the else branches of type assertions
32
33 ### Changed checks {#checks-changed}
34
35 The following checks have been improved:
36
37 - {{< check "S1001" >}} now simplifies more loops
38 - {{< check "S1038" >}} now simplifies formatted printing in `log` and `testing`, in addition to `fmt`
39 - {{< check "SA1019" >}} no longer flags deprecated API in the Go standard library if it doesn't know when the API was
40 deprecated. This is to avoid false positives when using older versions of Staticcheck on newer versions of Go, in
41 particular Go's `master` branch.
42 - {{< check "SA1020" >}} no longer flags `net/http.ListenAndServe` with a completely empty address
43 - {{< check "ST1001" >}} various packages of `github.com/mmcloughlin/avo` have been whitelisted by default
44 - {{< check "ST1008" >}} no longer flags functions that return `(..., error, bool)`
45 - {{< check "ST1018" >}} no longer flags emoji sequences
46 - {{< check "ST1023" >}} no longer makes erroneous suggestions
47 - Numerous checks have a better understanding of integer literals and can detect mistakes involving unconventional
48 literals such as `---1` instead of `-1`
49 - Some runtime crashes have been fixed
50
51 ## Staticcheck 2022.1.1 release notes {#2022.1.1}
52
53 This release addresses the following false positives, crashes, and infinite loops:
54
55 - {{< check "SA1026" >}} and {{< check "SA5008" >}} no longer get stuck in infinite loops when code attempts to marshal cyclic pointer types ({{< issue "1202" >}})
56 - U1000 no longer crashes when code contains mutually recursive type instantiations ({{< issue "1247" >}})
57 - U1000 no longer crashes when generic functions use composite literals of type parameter types ({{< commit "0ccdb5c9dad7e96a8e3a3136738192491b37dbdb" >}})
58 - {{< check "ST1021" >}} now understands type names that are also English articles ({{< issue "1187" >}})
59 - {{< check "SA4023" >}} no longer gets confused by the nilness of type parameters ({{< issue "1242" >}})
60 - Some checks no longer crash when trying to generate automated code fixes that involve function literals ({{< issue "1134" >}})
61 - {{< check "SA1026" >}} no longer claims that `encoding/json` cannot marshal generic maps ([golang/go#52467](https://golang.org/issue/52467))
62 - The `binary` format has been improved to handle OS-specific file paths correctly, in turn making the `-merge` flag work more reliably ({{< commit "1846305a946b13d350894512c7ac1e5ed71dc331" >}})
63 - When using the `-merge` or `-matrix` flags, diagnostics reported by {{< check "SA4008" >}} now have to occur in all runs to be reported, reducing the number of false positives ({{< commit "0e678cbe1c8b3f09ac481673453886b1afc9906a" >}})
64 - U1000 now understands struct type conversions involving type parameters, reducing the number of false positives ({{< commit "90804df0287d9265e565bcabbe19568efbe374fa" >}})
65
66 ## Staticcheck 2022.1.2 release notes {#2022.1.2}
67
68 This release addresses the following false positives, crashes, infinite loops, and performance issues:
69
70 - For certain packages that contain tens of thousands of types and methods, such as those generated by
71 [ygot](https://github.com/openconfig/ygot), Staticcheck now finishes [much
72 faster](https://github.com/openconfig/featureprofiles/pull/181#issuecomment-1119250596).
73 - Several infinite loops when handling recursive type parameters have been fixed
74 - {{< check "S1009" >}} no longer mistakes user-defined functions named `len` for the builtin ({{< issue "1181" >}})
75 - {{< check "ST1015" >}} no longer reorders `switch` statements if their order is significant due to the use of `fallthrough` ({{< issue "1188" >}})
76 - {{< check "SA1013" >}} now detects constants more robustly, avoiding both false negatives and false positives.
77 Furthermore, it makes sure that offending methods implement io.Seeker and doesn't just rely on the name `Seek` ({{< issue "1213" >}}).
78 - {{< check "SA5008" >}} now understands more third-party extensions to `json` struct tags
79 - A crash involving functions named `_` has been fixed ({{< issue "1268" >}})
80 - A crash involving slicing type parameters of type `string | []byte` has been fixed ({{< issue "1270" >}})
81 - {{< check "SA1019" >}} now handles imports of deprecated standard library packages in the same way it handles other
82 deprecated API, taking the targeted Go version into consideration ({{< issue "1117" >}})
83
84 Additionally it is strongly recommended to use Go 1.18.2 for building Staticcheck, as it fixes further generics-related
85 bugs in the type checker.
86
87 ## Staticcheck 2022.1.3 release notes {#2022.1.3}
88
89 This release addresses the following issues:
90
91 - Staticcheck maintains a cache to speed up repeated runs. This cache needs to be pruned regularly to keep its size in
92 check. This is meant to happen automatically, but it hasn't since Staticcheck 2020.2. This release corrects that ({{<
93 issue "1283" >}}.)
94 - Some type sets containing both bidirectional and unidirectional channels would lead to panics ({{< issue "1304" >}})