1 <ul class="changes-toc">
2 <li><a href="#introduction">Introduction to Staticcheck 2020.1</a></li>
3 <li><a href="#ui-improvements">UI improvements</a></li>
4 <li><a href="#caching">Better caching</a></li>
5 <li><a href="#checks">Checks</a><ul>
6 <li><a href="#checks-new">New checks</a></li>
7 <li><a href="#checks-changed">Changed checks</a></li>
9 <li><a href="#bugs">General bug fixes</a></li>
10 <li><a href="#2020.1.1">Staticcheck 2020.1.1 release notes</a></li>
11 <li><a href="#2020.1.2">Staticcheck 2020.1.2 release notes</a></li>
12 <li><a href="#2020.1.3">Staticcheck 2020.1.3 release notes</a></li>
13 <li><a href="#2020.1.4">Staticcheck 2020.1.4 release notes</a></li>
14 <li><a href="#2020.1.5">Staticcheck 2020.1.5 release notes</a></li>
17 <h2 id="introduction">Introduction to Staticcheck 2020.1</h2>
20 Staticcheck 2020.1 introduces UI improvements, speed enhancements, and
21 a number of <a href="#checks-new">new</a> as well as <a href="#checks-changed">improved</a> checks. Additionally, it is the
22 first release to support the upcoming Go 1.14.
25 <h2 id="ui-improvements">UI improvements</h2>
28 We've improved the output of the <code>staticcheck</code> command as well as
29 Staticcheck's integration with <a href="https://github.com/golang/tools/tree/master/gopls">gopls</a> to make it easier to understand
30 the problems that are being reported.
34 Related information describes the source of a problem, or why
35 Staticcheck believes that there is a problem. Take the following
36 piece of code for example:
40 <pre><code>func fn(x *int) {
42 log.Println("x is nil, returning")
49 Staticcheck 2020.1 will produce the following output:
52 <pre><code>foo.go:6:14: possible nil pointer dereference (SA5011)
53 foo.go:2:5: this check suggests that the pointer can be nil</code></pre>
56 The actual problem that is being reported is the "possible nil pointer
57 dereference". Staticcheck also explains why it believes that <code>x</code> might
58 be nil, namely the comparison on line 2.
62 When using the <a href="/docs/formatters#text"><code>text</code></a> or <a href="/docs/formatters#stylish"><code>stylish</code></a> formatters, related information will
63 appear as indented lines. The <a href="/docs/formatters#json"><code>json</code></a> formatter adds a new field
64 <code>related</code> to problems, containing position information as well as the
65 message. Editors that use gopls will also display the related
70 Related information should make it easier to understand why Staticcheck
71 is flagging code, and how to fix problems.
75 Integration with gopls has seen some other improvements as well¹. We
76 now emit better position information that more accurately reflects the
77 true source of a problem. The most obvious example is that a missing
78 package comment will no longer underline the entire file. Similarly,
79 invalid function arguments will be highlighted individually, instead
80 of highlighting the call as a whole. Finally, some problems can now be
81 automatically fixed by using quick fixes.
85 ¹: due to the nature of Staticcheck's integration with gopls, gopls
86 will need to update their dependency on Staticcheck before benefiting
90 <h2 id="caching">Better caching</h2>
93 The 2019.2 release introduced caching to Staticcheck, greatly speeding
94 up repeated runs. However, the caching only applied to dependencies;
95 the packages under analysis still had to be analyzed anew on every
96 invocation to compute the list of problems. Staticcheck 2020.1
97 introduces caching of problems found, so that repeat runs for
98 unchanged packages are virtually instantaneous.
101 <h2 id="checks">Checks</h2>
102 <h3 id="checks-new">New checks</h3>
105 Numerous new checks have been added in this release:
109 <li>{{ check "S1035" }} flags redundant calls to <code>net/http.CanonicalHeaderKey</code>.</li>
110 <li>{{ check "S1036" }} flags unnecessary guards around map accesses.</li>
111 <li>{{ check "S1037" }} flags unnecessarily elaborate ways of sleeping.</li>
112 <li>{{ check "S1038" }} flags unnecessary uses of <code>fmt.Sprintf</code>, such as <code>fmt.Println(fmt.Sprintf(...))</code>.</li>
113 <li>{{ check "S1039" }} flags uses of <code>fmt.Sprint</code> with single string literals.</li>
114 <li>{{ check "SA1028" }} flags uses of <code>sort.Slice</code> on non-slices.</li>
115 <li>{{ check "SA1029" }} flags inappropriate keys in calls to context.WithValue.</li>
116 <li>{{ check "SA4022" }} flags comparisons of the kind <code>if &x == nil</code>.</li>
117 <li>{{ check "SA5010" }} flags impossible type assertions.</li>
118 <li>{{ check "SA5011" }} flags potential nil pointer dereferences.</li>
119 <li>{{ check "ST1019" }} flags duplicate imports.</li>
120 <li>{{ check "ST1020" }} checks the documentation of exported functions.</li>
121 <li>{{ check "ST1021" }} checks the documentation of exported types.</li>
122 <li>{{ check "ST1022" }} checks the documentation of exported variables and constants.</li>
126 {{ check "ST1020" }}, {{ check "ST1021" }} and {{ check "ST1022" }} are not enabled by default.
129 <h3 id="checks-changed">Changed checks</h3>
132 Several checks have been improved:
136 <li>{{ check "S1036" }} detects more kinds of unnecessary guards around map accesses.</li>
137 <li>{{ check "S1008" }} reports more easily understood diagnostics.</li>
138 <li>{{ check "S1025" }} no longer suggests using <code>v.String()</code> instead of <code>fmt.Sprintf("%s", v)</code> when <code>v</code> is a <code>reflect.Value</code>. <code>fmt</code> gives special treatment to <code>reflect.Value</code> and the two results differ.</li>
139 <li>{{ check "SA1015" }} no longer flags uses of <code>time.Tick</code> in packages that implement <a href="https://github.com/spf13/cobra">Cobra</a> commands.</li>
140 <li>{{ check "SA1019" }} no longer misses references to deprecated packages when said packages have been vendored.</li>
141 <li>{{ check "SA4000" }} no longer flags comparisons of the kind <code>x == x</code> and <code>x != x</code> when `x` has a compound type involving floats.</li>
142 <li>{{ check "SA4003" }} no longer flags comparisons of the kind <code>x <= 0</code> when <code>x</code> is an unsigned integer. While it is true that <code>x <= 0</code> can be written more specifically as <code>x == 0</code>, this is not a helpful suggestion in reality. A lot of people use <code>x <= 0</code> as a defensive measure, in case <code>x</code> ever becomes signed. Also, unlike all the other warnings made in the check, <code>x <= 0</code> is neither a tautology nor a contradiction, it is merely less precise than it could be.</li>
143 <li>{{ check "SA4016" }} now detects silly bitwise ops of the form <code>x & k</code> where <code>k</code> is defined as <code>const k = iota</code>.</li>
144 <li>{{ check "SA4018" }} no longer flags self-assignments involving side effects; for example, it won't flag <code>x[fn()] = x[fn()]</code> if <code>fn</code> isn't pure.</li>
145 <li>{{ check "SA5008" }} now permits duplicate instances of various struct tags used by <code>github.com/jessevdk/go-flags</code>.</li>
146 <li>{{ check "SA5009" }} now correctly recognizes that <code>unsafe.Pointer</code> is a pointer type that can be used with verbs such as <code>%p</code>. Furthermore, it validates calls to <code>golang.org/x/xerrors.Errorf</code>.</li>
147 <li>{{ check "SA5009" }} now understands <code>fmt.Printf</code> verbs that were changed and added in Go 1.13. Specifically, it now recognizes the new <code>%O</code> verb, and allows the use of <code>%x</code> and <code>%X</code> on floats and complex numbers.</li>
148 <li>{{ check "ST1003" }} has learned about several new initialisms.</li>
149 <li>{{ check "ST1011" }} no longer misses variable declarations with inferred types.</li>
150 <li>{{ check "ST1016" }} now ignores the names of method receivers of methods declared in generated files.</li>
151 <li>{{ check "ST1020" }}, {{ check "ST1021" }}, and {{ check "ST1022" }} no longer enforce comment style in generated code.</li>
154 <h2 id="bugs">General bug fixes</h2>
157 The following bugs were fixed:
161 <li>A race condition in the {{ check "U1000" }} check could occasionally lead to sporadic false positives.</li>
162 <li>Some files generated by <em>goyacc</em> weren't recognized as being generated.</li>
163 <li><code>staticcheck</code> no longer fails to check packages that consist exclusively of tests.</li>
166 <h2 id="2020.1.1">Staticcheck 2020.1.1 release notes</h2>
169 The 2020.1 release neglected to update the version string stored in
170 the binary, causing <code>staticcheck -version</code> to incorrectly emit <code>(no version)</code>.
173 <h2 id="2020.1.2">Staticcheck 2020.1.2 release notes</h2>
176 The 2020.1.1 release incorrectly identified itself as version 2020.1.
179 <h2 id="2020.1.3">Staticcheck 2020.1.3 release notes</h2>
182 This release fixes two bugs involving <code>//lint:ignore</code> directives:
186 When ignoring U1000 and checking a package that contains tests,
187 Staticcheck would incorrectly complain that the linter directive
188 didn't match any problems, even when it did.
192 On repeated runs, the position information for a <q>this linter directive didn't match anything</q> report
193 would either be missing, or be wildly incorrect.
198 <h2 id="2020.1.4">Staticcheck 2020.1.4 release notes</h2>
201 This release adds special handling for imports of the
202 deprecated <code>github.com/golang/protobuf/proto</code> package.
206 <a href="https://github.com/golang/protobuf">github.com/golang/protobuf</a>
207 has deprecated the <code>proto</code> package, but
208 their <code>protoc-gen-go</code> still imports the package and uses
209 one of its constants, <q>to enforce a weak dependency on a
210 sufficiently new version of the legacy package</q>.
214 Staticcheck would flag the import of this deprecated package in all
215 code generated by protoc-gen-go. Instead of forcing the project to
216 change their project structure, we choose to ignore such imports in
217 code generated by protoc-gen-go. The import still gets flagged in code
218 not generated by protoc-gen-go.
222 You can find more information about this in the <a href="https://github.com/golang/protobuf/issues/1077">upstream issue</a>.
225 <h2 id="2020.1.5">Staticcheck 2020.1.5 release notes</h2>
228 This release fixes a <a href="https://github.com/dominikh/go-tools/issues/806">crash in the pattern matching engine</a>
229 and a <a href="https://github.com/dominikh/go-tools/issues/733">false positive in SA4006</a>.