Debian Codegraph @

website/content/changes/2019.1.md

raw
1 ---
2 title: Staticcheck 2019.1 release notes
3 linkTitle: 2019.1
4 weight: -2
5 ---
6
7 ## Big restructuring
8
9 At the core of the 2019.1 release lies the grand restructuring of all of the Staticcheck tools.
10 All of the individual checkers, as well as megacheck, have been merged into a single tool,
11 which is simply called `staticcheck`.
12 From this point forward, `staticcheck` will be _the_ static analyzer for Go code.
13 It will cover all of the existing categories of checks – bugs, simplifications, performance –
14 as well as future categories, such as the new style checks.
15
16 This change makes a series of simplifications possible.
17 Per-tool command line flags in megacheck have been replaced with unified flags
18 (`-checks` and `-fail`)
19 that operate on arbitrary subsets of checks.
20 Consumers of the JSON output no longer need to know about different checker names
21 and can instead rely solely on user-controllable severities.
22 And not to be neglected: gone is the silly name of _megacheck_.
23
24 This change will require some changes to your pipelines.
25 Even though the gosimple, unused, and megacheck tools still exist, they have been deprecated
26 and will be removed in the next release of staticcheck.
27 Additionally, megacheck's `-<tool>.exit-non-zero` flags have been rendered inoperable.
28 Instead, you will have to use the `-fail` flag.
29 Furthermore,, `-fail` defaults to `all`, meaning all checks will cause non-zero exiting.
30 Previous versions of megacheck had different defaults for different checkers, trying to guess the user's intention.
31 Instead of guessing, staticcheck expects you to provide the correct flags.
32
33 Since all of the tools have been merged into staticcheck, it will no longer run just one group of checks.
34 This may lead to additional problems being reported.
35 To restore the old behavior, you can use the new `-checks` flag.
36 `-checks "SA*"` will run the same set of checks that the old staticcheck tool did.
37 The same flag should be used in place of megacheck's – now deprecated – `-<tool>.enabled` flags.
38
39 Details on all of the command-line flags can be found [in the documentation.]({{< relref "/docs/#cli" >}})
40
41 ## Configuration files
42
43 Staticcheck 2019.1 adds support for per-project configuration files.
44 With these it will be possible to standardize and codify linter settings, the set of enabled checks, and more.
45 Please see the [documentation page on configuration]({{< relref "/docs/#configuration" >}}) for all the details!
46
47 ## Build system integration
48
49 Beginning with this release, staticcheck calls out to the tools of the underlying build system
50 (`go` for most people) to determine the list of Go files to process.
51 This change should not affect most people.
52 It does, however, have some implications:
53 the system that staticcheck runs on needs access to a full Go toolchain –
54 just the source code of the standard library no longer suffices.
55 Furthermore, setting `GOROOT` to use a different Go installation no longer works as expected.
56 Instead, `PATH` has to be modified so that `go` resolves to the desired Go command.
57
58 This change has been necessary to support Go modules.
59 Additionally, it will allow us to support alternative build systems such as Bazel in the future.
60
61 ## Handling of broken packages
62
63 We have redesigned the way staticcheck handles broken packages.
64 Previously, if you ran `staticcheck ...` and any package wouldn't compile,
65 staticcheck would refuse to check any packages whatsoever.
66 Now, it will skip broken packages, as well as any of their dependents, and check only the remaining packages.
67 Any build errors that are encountered will be reported as problems.
68
69 ## Checks
70
71 ### New checks
72
73 Staticcheck 2019.1 adds a new category of checks, ST1.
74 ST1 contains checks for common style violations – poor variable naming, incorrectly formatted comments and the like.
75 It brings the good parts of [golint](https://github.com/golang/lint) to staticcheck,
76 and adds some checks of its own.
77
78 In addition, some other checks have been added.
79
80 {{< check "S1032" >}} recommends replacing `sort.Sort(sort.StringSlice(...))` with `sort.Strings(...)`;
81 similarly for other types that have helpers for sorting.
82
83 {{< check "SA9004" >}} flags groups of constants where only the first one is given an explicit type.
84
85 {{< check "SA1025" >}} checks for incorrect uses of `(*time.Timer).Reset`.
86
87 ### Changed checks
88
89 Several checks have been tweaked, either making them more accurate or finding more issues.
90
91 {{< check "S1002" >}} no longer applies to code in tests.
92 While `if aBool == true` is usually an anti-pattern,
93 it can feel more natural in unit tests,
94 as it mirrors the `if got != want` pattern.
95
96 {{< check "S1005" >}} now flags `for x, _ := range` because of the unnecessary blank assignment.
97
98 {{< check "S1007" >}} no longer suggests using raw strings for regular expressions containing backquotes.
99
100 {{< check "S1016" >}} now considers the targeted Go version.
101 It will no longer suggest type conversions between struct types with different field tags
102 unless Go 1.8 or later is being targeted.
103
104 {{< check "SA1000" >}} now checks arguments passed to the `regexp.Match` class of functions.
105
106 {{< check "SA1014" >}} now checks arguments passed to `(*encoding/xml.Decoder).DecodeElement`.
107
108 {{< check "SA6002" >}} now realizes that unsafe.Pointer is a pointer.
109
110 {{< check "U1000" >}} has fewer false positives in the presence of embedding.
111
112 ### Removed checks
113
114 {{< check "S1013" >}} has been removed,
115 no longer suggesting replacing `if err != nil { return err }; return nil` with `return err`.
116 This check has been the source of contention and more often than not, it reduced the consistency of the surrounding code.
117
118 ## Deprecation notices
119
120 This release deprecates various features of staticcheck.
121 These features will be removed in the next release.
122
123 As already explained earlier, the _unused_, _gosimple_, and _megacheck_ tools
124 have been replaced by _staticcheck_.
125 Similarly, the flags `-<tool>.enabled` and `-<tool>.exit-non-zero`
126 have been replaced by `-checks` and `-fail`.
127 Finally, the `-ignore` flag has been replaced
128 by [linter directives]({{< relref "/docs/#ignoring-problems" >}}).
129
130 ## Binary releases
131
132 Beginning with this release, we're publishing
133 [prebuilt binaries to GitHub](https://github.com/dominikh/go-tools/releases).
134 These releases still require a functioning Go installation in order to operate, however.
135
136 ## Other changes
137
138 We've removed the `-min_confidence` flag.
139 This flag hasn't been doing anything for years.
140
141 A new formatter called [Stylish]({{< relref "/docs/running-staticcheck/cli/formatters" >}}) (usable with `-f stylish`)
142 provides output that is designed for easier consumption by humans.
143
144 Due to the restructuring of checkers, the `checker` field in JSON output has been replaced
145 with the `severity` field.
146
147 ## Staticcheck 2019.1.1 Release Notes {#2019.1.1}
148
149 The 2019.1.1 release of Staticcheck is the first bug fix release, fixing several bugs and improving performance.
150
151 ### Changes
152
153 - The ST category of checks no longer flag style issues of
154 aliased types when the aliased type exists in a package
155 we aren't explicitly checking. This avoids crashes and
156 erratic error reports.
157 - Compiler errors now have correct position information.
158 - A crash in the Stylish reporter has been fixed.
159 - We no longer flag unused objects that belong to cgo internals.
160 - The {{< check "U1000" >}} check has been optimized, reducing its memory
161 usage and runtime.