.gitignore added
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / honnef.co / go / tools@v0.1.1 / doc / 2020.1.html
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>
8   </ul></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>
15   <li><a href="#2020.1.6">Staticcheck 2020.1.6 release notes</a></li>
16 </ul>
17
18 <h2 id="introduction">Introduction to Staticcheck 2020.1</h2>
19
20 <p>
21   Staticcheck 2020.1 introduces UI improvements, speed enhancements, and
22   a number of <a href="#checks-new">new</a> as well as <a href="#checks-changed">improved</a> checks. Additionally, it is the
23   first release to support the upcoming Go 1.14.
24 </p>
25
26 <h2 id="ui-improvements">UI improvements</h2>
27
28 <p>
29   We've improved the output of the <code>staticcheck</code> command as well as
30   Staticcheck's integration with <a href="https://github.com/golang/tools/tree/master/gopls">gopls</a> to make it easier to understand
31   the problems that are being reported.
32 </p>
33
34 <p>
35   Related information describes the source of a problem, or why
36   Staticcheck believes that there is a problem. Take the following
37   piece of code for example:
38 </p>
39
40
41 <pre><code>func fn(x *int) {
42         if x == nil {
43                 log.Println("x is nil, returning")
44         }
45         // lots of code here
46         log.Println(*x)
47 }</code></pre>
48
49 <p>
50   Staticcheck 2020.1 will produce the following output:
51 </p>
52
53 <pre><code>foo.go:6:14: possible nil pointer dereference (SA5011)
54         foo.go:2:5: this check suggests that the pointer can be nil</code></pre>
55
56 <p>
57   The actual problem that is being reported is the "possible nil pointer
58   dereference". Staticcheck also explains why it believes that <code>x</code> might
59   be nil, namely the comparison on line 2.
60 </p>
61
62 <p>
63   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
64   appear as indented lines. The <a href="/docs/formatters#json"><code>json</code></a> formatter adds a new field
65   <code>related</code> to problems, containing position information as well as the
66   message. Editors that use gopls will also display the related
67   information.
68 </p>
69
70 <p>
71   Related information should make it easier to understand why Staticcheck
72   is flagging code, and how to fix problems.
73 </p>
74
75 <p>
76   Integration with gopls has seen some other improvements as well¹. We
77   now emit better position information that more accurately reflects the
78   true source of a problem. The most obvious example is that a missing
79   package comment will no longer underline the entire file. Similarly,
80   invalid function arguments will be highlighted individually, instead
81   of highlighting the call as a whole. Finally, some problems can now be
82   automatically fixed by using quick fixes.
83 </p>
84
85 <p>
86   ¹: due to the nature of Staticcheck's integration with gopls, gopls
87   will need to update their dependency on Staticcheck before benefiting
88   from these changes.
89 </p>
90
91 <h2 id="caching">Better caching</h2>
92
93 <p>
94   The 2019.2 release introduced caching to Staticcheck, greatly speeding
95   up repeated runs. However, the caching only applied to dependencies;
96   the packages under analysis still had to be analyzed anew on every
97   invocation to compute the list of problems. Staticcheck 2020.1
98   introduces caching of problems found, so that repeat runs for
99   unchanged packages are virtually instantaneous.
100 </p>
101
102 <h2 id="checks">Checks</h2>
103 <h3 id="checks-new">New checks</h3>
104
105 <p>
106   Numerous new checks have been added in this release:
107 </p>
108
109 <ul>
110   <li>{{ check "S1035" }} flags redundant calls to <code>net/http.CanonicalHeaderKey</code>.</li>
111   <li>{{ check "S1036" }} flags unnecessary guards around map accesses.</li>
112   <li>{{ check "S1037" }} flags unnecessarily elaborate ways of sleeping.</li>
113   <li>{{ check "S1038" }} flags unnecessary uses of <code>fmt.Sprintf</code>, such as <code>fmt.Println(fmt.Sprintf(...))</code>.</li>
114   <li>{{ check "S1039" }} flags uses of <code>fmt.Sprint</code> with single string literals.</li>
115   <li>{{ check "SA1028" }} flags uses of <code>sort.Slice</code> on non-slices.</li>
116   <li>{{ check "SA1029" }} flags inappropriate keys in calls to context.WithValue.</li>
117   <li>{{ check "SA4022" }} flags comparisons of the kind <code>if &x == nil</code>.</li>
118   <li>{{ check "SA5010" }} flags impossible type assertions.</li>
119   <li>{{ check "SA5011" }} flags potential nil pointer dereferences.</li>
120   <li>{{ check "ST1019" }} flags duplicate imports.</li>
121   <li>{{ check "ST1020" }} checks the documentation of exported functions.</li>
122   <li>{{ check "ST1021" }} checks the documentation of exported types.</li>
123   <li>{{ check "ST1022" }} checks the documentation of exported variables and constants.</li>
124 </ul>
125
126 <p>
127   {{ check "ST1020" }}, {{ check "ST1021" }} and {{ check "ST1022" }} are not enabled by default.
128 </p>
129
130 <h3 id="checks-changed">Changed checks</h3>
131
132 <p>
133   Several checks have been improved:
134 </p>
135
136 <ul>
137   <li>{{ check "S1036" }} detects more kinds of unnecessary guards around map accesses.</li>
138   <li>{{ check "S1008" }} reports more easily understood diagnostics.</li>
139   <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>
140   <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>
141   <li>{{ check "SA1019" }} no longer misses references to deprecated packages when said packages have been vendored.</li>
142   <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>
143   <li>{{ check "SA4003" }} no longer flags comparisons of the kind <code>x &lt;= 0</code> when <code>x</code> is an unsigned integer. While it is true that <code>x &lt;= 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 &lt;= 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 &lt;= 0</code> is neither a tautology nor a contradiction, it is merely less precise than it could be.</li>
144   <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>
145   <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>
146   <li>{{ check "SA5008" }} now permits duplicate instances of various struct tags used by <code>github.com/jessevdk/go-flags</code>.</li>
147   <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>
148   <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>
149   <li>{{ check "ST1003" }} has learned about several new initialisms.</li>
150   <li>{{ check "ST1011" }} no longer misses variable declarations with inferred types.</li>
151   <li>{{ check "ST1016" }} now ignores the names of method receivers of methods declared in generated files.</li>
152   <li>{{ check "ST1020" }}, {{ check "ST1021" }}, and {{ check "ST1022" }} no longer enforce comment style in generated code.</li>
153 </ul>
154
155 <h2 id="bugs">General bug fixes</h2>
156
157 <p>
158   The following bugs were fixed:
159 </p>
160
161 <ul>
162   <li>A race condition in the {{ check "U1000" }} check could occasionally lead to sporadic false positives.</li>
163   <li>Some files generated by <em>goyacc</em> weren't recognized as being generated.</li>
164   <li><code>staticcheck</code> no longer fails to check packages that consist exclusively of tests.</li>
165 </ul>
166
167
168 <h2 id="2020.1.1">Staticcheck 2020.1.1 release notes</h2>
169
170 <p>
171   The 2020.1 release neglected to update the version string stored in
172   the binary, causing <code>staticcheck -version</code> to incorrectly emit <code>(no version)</code>.
173 </p>
174
175 <h2 id="2020.1.2">Staticcheck 2020.1.2 release notes</h2>
176
177 <p>
178   The 2020.1.1 release incorrectly identified itself as version 2020.1.
179 </p>
180
181 <h2 id="2020.1.3">Staticcheck 2020.1.3 release notes</h2>
182
183 <p>
184   This release fixes two bugs involving <code>//lint:ignore</code> directives:
185
186   <ul>
187     <li>
188       When ignoring U1000 and checking a package that contains tests,
189       Staticcheck would incorrectly complain that the linter directive
190       didn't match any problems, even when it did.
191     </li>
192
193     <li>
194       On repeated runs, the position information for a <q>this linter directive didn't match anything</q> report
195       would either be missing, or be wildly incorrect.
196     </li>
197   </ul>
198 </p>
199
200 <h2 id="2020.1.4">Staticcheck 2020.1.4 release notes</h2>
201
202 <p>
203   This release adds special handling for imports of the
204   deprecated <code>github.com/golang/protobuf/proto</code> package.
205 </p>
206
207 <p>
208   <a href="https://github.com/golang/protobuf">github.com/golang/protobuf</a>
209   has deprecated the <code>proto</code> package, but
210   their <code>protoc-gen-go</code> still imports the package and uses
211   one of its constants, <q>to enforce a weak dependency on a
212   sufficiently new version of the legacy package</q>.
213 </p>
214
215 <p>
216   Staticcheck would flag the import of this deprecated package in all
217   code generated by protoc-gen-go. Instead of forcing the project to
218   change their project structure, we choose to ignore such imports in
219   code generated by protoc-gen-go. The import still gets flagged in code
220   not generated by protoc-gen-go.
221 </p>
222
223 <p>
224   You can find more information about this in the <a href="https://github.com/golang/protobuf/issues/1077">upstream issue</a>.
225 </p>
226
227 <h2 id="2020.1.5">Staticcheck 2020.1.5 release notes</h2>
228
229 <p>
230   This release fixes a <a href="https://github.com/dominikh/go-tools/issues/806">crash in the pattern matching engine</a>
231   and a <a href="https://github.com/dominikh/go-tools/issues/733">false positive in SA4006</a>.
232 </p>
233
234 <h2 id="2020.1.6">Staticcheck 2020.1.6 release notes</h2>
235
236 <p>
237   This release makes the following fixes and improvements:
238 </p>
239
240 <ul>
241   <li>Staticcheck no longer panics when encountering files that have the following comment: <code>// Code generated DO NOT EDIT.</code></li>
242   <li>{{ check "SA4016" }} no longer panics when checking bitwise operations that involve dot-imported identifiers.</li>
243   <li>Fixed the suggested fix offered by {{ check "S1004" }}.</li>
244   <li>Fixed a false positive involving byte arrays in {{ check "SA5009" }}.</li>
245   <li>Fixed a false positive involving named byte slice types in {{ check "SA5009" }}.</li>
246   <li>Added another heuristic to avoid flagging function names in error messages in {{ check "ST1005" }}.</li>
247   <li>{{ check "SA3000" }} will no longer flag missing calls to os.Exit in TestMain functions if targeting Go 1.15 or newer.</li>
248 </ul>
249
250