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