| 1 |
--- |
| 2 |
title: Staticcheck 2021.1 release notes |
| 3 |
linkTitle: "2021.1 (v0.2.0)" |
| 4 |
weight: -6 |
| 5 |
--- |
| 6 |
|
| 7 |
## UI improvements {#ui-improvements} |
| 8 |
|
| 9 |
The new `-list-checks` flag lists all available checks, showing each check's identifier and one-line description. |
| 10 |
You can use the existing `-explain` flag to find out more about each individual check. |
| 11 |
|
| 12 |
### Targeted Go version {#targeted-go-version} |
| 13 |
|
| 14 |
Some checks in Staticcheck adjust their behavior based on the targeted Go version. For example, the suggestion to use `for range` instead of `for _ = range` does not apply to Go 1.3 and earlier. |
| 15 |
|
| 16 |
In the past, the default Go version that was targeted was the version that Staticcheck had been compiled with. For most users, this meant that it targeted the latest Go release. |
| 17 |
Going forward, we will default to the Go version declared in `go.mod` via the `go` directive. |
| 18 |
Even though this value does not exactly correspond to the module's minimum supported Go version, it is still a better apprximation than "whatever Go version Staticcheck has been compiled with", |
| 19 |
and should work fine for most users. |
| 20 |
|
| 21 |
As before, the targeted Go version can be explicitly set by using the `-go` flag. |
| 22 |
|
| 23 |
## Checks {#checks} |
| 24 |
|
| 25 |
### New checks {#checks-new} |
| 26 |
|
| 27 |
The following new checks have been added: |
| 28 |
|
| 29 |
- {{< check "S1040" >}} flags type assertions from an interface type to itself |
| 30 |
- {{< check "SA1030" >}} flags invalid arguments to various functions in the `strconv` package |
| 31 |
- {{< check "SA4005" >}} flags assignments to fields on value receivers that intended the receiver to be a pointer instead |
| 32 |
- {{< check "SA4024" >}} flags pointless comparisons of the values of `len` and `cap` with zero |
| 33 |
- {{< check "SA4025" >}} flags suspicious integer division that results in zero, such as `2 / 3` |
| 34 |
- {{< check "SA4026" >}} flags constant expressions that try to express [negative zero](https://en.wikipedia.org/wiki/Signed_zero) |
| 35 |
- {{< check "SA4027" >}} flags no-op attempts at modifying a `(*net/url.URL)`'s query string |
| 36 |
- {{< check "ST1023" >}} flags variable declarations of the form `var x T = v` where the type `T` is redundant; this check is disabled by default |
| 37 |
|
| 38 |
|
| 39 |
### Changed checks {#checks-changed} |
| 40 |
|
| 41 |
The following checks have been improved: |
| 42 |
|
| 43 |
- {{< check "S1025" >}} now recommends converting byte slices to strings instead of using `fmt.Sprintf` |
| 44 |
- {{< check "S1008" >}} includes fewer unnecessary parentheses and double negations in its suggested fixes |
| 45 |
- {{< check "S1017" >}} is now able to flag calls that use string literals and integer literals |
| 46 |
- {{< check "SA9005" >}} now includes the value's type in its output |
| 47 |
- {{< check "ST1000" >}}, {{< check "ST1020" >}}, {{< check "ST1021" >}}, and {{< check "ST1022" >}} no longer flag effectively empty comments, including those that consist entirely of directives |
| 48 |
|
| 49 |
## Restructured documentation {#documentation} |
| 50 |
|
| 51 |
The documentation on [the website](https://staticcheck.dev) has been restructured and hopefully made more approachable. |
| 52 |
Instead of being one long document, it is now split into multiple smaller articles. |
| 53 |
In the future, more articles that look at specific aspects of Staticcheck will be added. |
| 54 |
|
| 55 |
## Better integration with gopls {#gopls} |
| 56 |
|
| 57 |
Several behind the scenes changes prepare this release for better integration with [gopls](https://github.com/golang/tools/blob/master/gopls/README.md). |
| 58 |
This will include more accurate severities for diagnostics as well as numerous new refactorings. |
| 59 |
These improvements will be part of a future gopls release. |
| 60 |
|
| 61 |
## Deletion of rdeps {#rdeps} |
| 62 |
|
| 63 |
The rdeps tool has been deleted. |
| 64 |
This was a GOPATH-centric tool that allowed finding all reverse dependencies of a Go package. |
| 65 |
Both the move to Go modules as well as the emergence of much better tooling for inspecting dependencies (such as [goda](https://github.com/loov/goda)) has made rdeps redundant. |
| 66 |
|
| 67 |
## Staticcheck 2021.1.1 release notes {#2021.1.1} |
| 68 |
|
| 69 |
This release adds support for new language features in Go 1.17, |
| 70 |
namely conversions from slices to array pointers, |
| 71 |
the unsafe.Add function, |
| 72 |
and the unsafe.Slice function. |
| 73 |
|
| 74 |
Additionally, it fixes the following false positives: |
| 75 |
|
| 76 |
- {{< check "ST1000" >}} no longer flags package docs that start with whitespace if they're otherwise well-formed. |
| 77 |
- {{< check "SA5002" >}} no longer prints one too many percent signs in its message. |
| 78 |
- {{< check "SA4000" >}} no longer flags comparisons between floats. |
| 79 |
- {{< check "SA4010" >}} no longer flags appends to slices that might share their backing array with other slices. |
| 80 |
- {{< check "SA5011" >}} no longer infers possible nil pointer dereferences from comparisons done outside of control flow constructs. |
| 81 |
This avoids false positives when using `assert`-style functions. |
| 82 |
See [issue 1022]({{< issueref 1022 >}}) for a concrete example. |
| 83 |
- {{< check "S1020" >}} no longer flags nested if statements when the inner statement has an else branch. |
| 84 |
- {{< check "SA5011" >}} no longer claims that indexing a nil slice will cause a nil pointer dereference. |
| 85 |
|
| 86 |
## Staticcheck 2021.1.2 release notes {#2021.1.2} |
| 87 |
|
| 88 |
This release fixes the following false positives: |
| 89 |
|
| 90 |
- {{< check "SA4000" >}} no longer flags operations involving the `math/rand` package. This is to allow patterns such as `rand.Intn(2) - rand.Intn(2)`. |
| 91 |
- {{< check "S1019" >}} no longer recommends replacing `make(map[X]Y, 0)` with `make(map[X]Y)` – the latter may allocate a small starting size. |
| 92 |
- {{< check "SA1026" >}} now more accurately implements the behavior of `encoding/json` and `encoding/xml`, which will lead to fewer false positives involving method sets or embedding. |
| 93 |
It might also find bugs that it previously missed. |
| 94 |
- Checks that are sensitive to control flow, such as {{< check "SA5011" >}}, now recognize functions from `k8s.io/klog` and `go.uber.org/zap` that affect control flow (`Panic` and `Fatal` related functions.) |
| 95 |
|
| 96 |
Furthermore, it fixes the following crashes: |
| 97 |
|
| 98 |
- Using `//lint:ignore U1000` on a type alias would crash. |
| 99 |
- Converting a slice to an array pointer, where the array type is a named type, would crash. |