1 <h2>Introduction to staticcheck 2017.2</h2>
4 The 2017.2 release of the staticcheck suite of tools focuses on
5 reducing friction – fewer false positives, more tools for suppressing
6 unwanted output, and JSON output for easier integration with other
12 <h3>Linter directives for ignoring problems</h3>
15 In the past, the only ways to ignore reported problems was by using
16 the <code>-ignore</code> flag. This led to overreaching ignore rules
17 which weren't maintained regularly. Now, <code>//lint:ignore</code> and
18 <code>//lint:file-ignore</code> comments can be used to ignore
19 problems, either on specific lines or file-wide. A full description of
20 these directives, their syntax and their behavior can be found
21 <a href="/docs#ignoring-problems">in the documentation.</a>
25 A related change adds the <code>-show-ignored</code> command line
26 flag, which outputs problems that would otherwise be ignored by
27 directives. This is primarily of use with the JSON output format,
28 for custom front ends.
31 <h3>Output formats</h3>
34 All staticcheck tools now support multiple output formats, selectable
35 with the <code>-f</code> flag.
39 Currently, two formats are supported. The first format is
40 <code>text</code>, which is the default and uses the existing terminal
41 output format. The other is <code>json</code>, which emits JSON. The
42 output is a stream of objects, allowing for a future streaming output
43 mode. Each object uses the following example schema:
47 "checker": "staticcheck",
50 "file": "/usr/lib/go/src/database/sql/sql_test.go",
54 "message": "this value of err is never used",
58 <h3>Control over the exit code of megacheck</h3>
61 Megacheck, the tool for running multiple checkers at once, now has
62 per checker flags for controlling the overall exit code. Previously,
63 megacheck would exit non-zero if any checker found a problem. Now it
64 is possible to configure for each checker whether it should cause a
65 non-zero exit, by using the <code>-<checker>.exit-non-zero</code>
66 flags. This flag defaults to false for <em>gosimple</em> and to true for
70 <h2>Changes to checks</h2>
72 <h3>Support for <code>NoCopy</code> in <em>unused</em></h3>
75 The <em>unused</em> tool now understands <code>NoCopy</code> sentinel types. The
76 <code>NoCopy</code> type, which is canonically a struct with no fields and only a
77 single, empty <code>Lock</code> method, can be used to mark structs as not safe
78 for copying. By declaring a field of this type, <em>go vet</em> will complain
79 when it sees instances of the struct being copied.
83 In the past, <em>unused</em> marked these fields as unused, now it ignores
87 <h3>Detection of deprecated identifiers</h3>
90 <span class="check-name" title="Using a deprecated function, variable, constant or field">SA1019</span> now
91 correctly identifies deprecated methods, in addition to fields and
92 package-level objects. Additionally, staticcheck now keeps track of
93 when each identifier in the Go standard library was deprecated, so
94 that using <code>-go <version></code> can correctly
95 ignore deprecation warnings that don't apply to the targeted Go
103 {{ check "SA4017" }} no
104 longer reports pure functions that are stubs – functions that
105 immediately panic or return a constant.
108 {{ check "SA5007" }} no
109 longer flags infinite recursion when the function call is spawned
114 now recognizes that <code>unsafe.Pointer</code> is
119 no longer suggests <code>for range</code> when targeting a version
123 {{ check "S1026" }} has been
124 removed. In some rare instances, copying a string is necessary, and
125 all common ways of doing this were incorrectly flagged by the check.
130 <h2>Other changes</h2>
134 The <code>-ignore</code> flag now supports ignoring checks in all packages,
135 by using <code>*</code> as the path.
138 <code>//line</code> directives are now being ignored when
139 reporting problems. That is, problems will always be reported for
140 the actual position in the Go files they occur.
143 From now on, only the first compilation error encountered will be
144 reported. The tools expect to be run on valid Go code and there
145 was little (if any) value in reporting all compilation errors
146 encountered, especially because simple errors can lead to many
151 <h2 id="2017.2.1">Staticcheck 2017.2.1 Release Notes</h2>
154 The 2017.2.1 release of the staticcheck suite of tools is the first
155 bug fix release, fixing one bug.
162 Staticcheck 2017.2 made the detection of deprecated objects
163 Go-version aware. Unfortunately, this only worked correctly for
164 fields and methods, but not package-level objects. This release
169 <h2 id="2017.2.2">Staticcheck 2017.2.2 Release Notes</h2>
172 The 2017.2.2 release of the staticcheck suite of tools is the second
173 bug fix release, fixing several bugs.
179 <li><em>unused</em>: correctly apply the NoCopy exemption when using the <code>-exported</code> flag.</li>
180 <li><em>keyify</em>: support external test packages (<code>package foo_test</code>)</li>
181 <li><em>staticcheck</em>: disable {{ check "SA4005" }} – the check, in its current form, is prone to false positives and will be reimplemented in a future release.</li>