Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / coc-go-data / tools / pkg / mod / honnef.co / go / tools@v0.0.1-2020.1.5 / 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 </ul>
16
17 <h2 id="introduction">Introduction to Staticcheck 2020.1</h2>
18
19 <p>
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.
23 </p>
24
25 <h2 id="ui-improvements">UI improvements</h2>
26
27 <p>
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.
31 </p>
32
33 <p>
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:
37 </p>
38
39
40 <pre><code>func fn(x *int) {
41         if x == nil {
42                 log.Println("x is nil, returning")
43         }
44         // lots of code here
45         log.Println(*x)
46 }</code></pre>
47
48 <p>
49   Staticcheck 2020.1 will produce the following output:
50 </p>
51
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>
54
55 <p>
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.
59 </p>
60
61 <p>
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
66   information.
67 </p>
68
69 <p>
70   Related information should make it easier to understand why Staticcheck
71   is flagging code, and how to fix problems.
72 </p>
73
74 <p>
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.
82 </p>
83
84 <p>
85   ¹: due to the nature of Staticcheck's integration with gopls, gopls
86   will need to update their dependency on Staticcheck before benefiting
87   from these changes.
88 </p>
89
90 <h2 id="caching">Better caching</h2>
91
92 <p>
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.
99 </p>
100
101 <h2 id="checks">Checks</h2>
102 <h3 id="checks-new">New checks</h3>
103
104 <p>
105   Numerous new checks have been added in this release:
106 </p>
107
108 <ul>
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>
123 </ul>
124
125 <p>
126   {{ check "ST1020" }}, {{ check "ST1021" }} and {{ check "ST1022" }} are not enabled by default.
127 </p>
128
129 <h3 id="checks-changed">Changed checks</h3>
130
131 <p>
132   Several checks have been improved:
133 </p>
134
135 <ul>
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 &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>
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>
152 </ul>
153
154 <h2 id="bugs">General bug fixes</h2>
155
156 <p>
157   The following bugs were fixed:
158 </p>
159
160 <ul>
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>
164 </ul>
165
166 <h2 id="2020.1.1">Staticcheck 2020.1.1 release notes</h2>
167
168 <p>
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>.
171 </p>
172
173 <h2 id="2020.1.2">Staticcheck 2020.1.2 release notes</h2>
174
175 <p>
176   The 2020.1.1 release incorrectly identified itself as version 2020.1.
177 </p>
178
179 <h2 id="2020.1.3">Staticcheck 2020.1.3 release notes</h2>
180
181 <p>
182   This release fixes two bugs involving <code>//lint:ignore</code> directives:
183
184   <ul>
185     <li>
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.
189     </li>
190
191     <li>
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.
194     </li>
195   </ul>
196 </p>
197
198 <h2 id="2020.1.4">Staticcheck 2020.1.4 release notes</h2>
199
200 <p>
201   This release adds special handling for imports of the
202   deprecated <code>github.com/golang/protobuf/proto</code> package.
203 </p>
204
205 <p>
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>.
211 </p>
212
213 <p>
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.
219 </p>
220
221 <p>
222   You can find more information about this in the <a href="https://github.com/golang/protobuf/issues/1077">upstream issue</a>.
223 </p>
224
225 <h2 id="2020.1.5">Staticcheck 2020.1.5 release notes</h2>
226
227 <p>
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>.
230 </p>