Debian Codegraph @

website/content/changes/2017.2.md

raw
1 ---
2 title: Staticcheck 2017.2 release notes
3 linkTitle: 2017.2
4 weight: -1
5 ---
6
7 The 2017.2 release of the staticcheck suite of tools focuses on
8 reducing friction – fewer false positives, more tools for suppressing
9 unwanted output, and JSON output for easier integration with other
10 tools.
11
12 ## New features
13
14 ### Linter directives for ignoring problems
15
16 In the past, the only ways to ignore reported problems was by using
17 the `-ignore` flag. This led to overreaching ignore rules
18 which weren't maintained regularly. Now, `//lint:ignore` and
19 `//lint:file-ignore` comments can be used to ignore
20 problems, either on specific lines or file-wide. A full description of
21 these directives, their syntax and their behavior can be found
22 in [the documentation]({{< relref "/docs/configuration#ignoring-problems" >}}).
23
24 A related change adds the `-show-ignored` command line
25 flag, which outputs problems that would otherwise be ignored by
26 directives. This is primarily of use with the JSON output format,
27 for custom front ends.
28
29 ### Output formats
30
31 All staticcheck tools now support multiple output formats, selectable
32 with the `-f` flag.
33
34 Currently, two formats are supported. The first format is
35 `text`, which is the default and uses the existing terminal
36 output format. The other is `json`, which emits JSON. The
37 output is a stream of objects, allowing for a future streaming output
38 mode. Each object uses the following example schema:
39
40 ```json
41 {
42 "checker": "staticcheck",
43 "code": "SA4006",
44 "location": {
45 "file": "/usr/lib/go/src/database/sql/sql_test.go",
46 "line": 2701,
47 "column": 5
48 },
49 "message": "this value of err is never used",
50 "ignored": false
51 }
52 ```
53
54 ### Control over the exit code of megacheck
55
56 Megacheck, the tool for running multiple checkers at once, now has
57 per checker flags for controlling the overall exit code. Previously,
58 megacheck would exit non-zero if any checker found a problem. Now it
59 is possible to configure for each checker whether it should cause a
60 non-zero exit, by using the `-&lt;checker&gt;.exit-non-zero`
61 flags. This flag defaults to false for _gosimple_ and to true for
62 the other checkers.
63
64 ## Changes to checks
65
66 ### Support for `NoCopy` in _unused_
67
68 The _unused_ tool now understands `NoCopy` sentinel types. The
69 `NoCopy` type, which is canonically a struct with no fields and only a
70 single, empty `Lock` method, can be used to mark structs as not safe
71 for copying. By declaring a field of this type, _go vet_ will complain
72 when it sees instances of the struct being copied.
73
74 In the past, _unused_ marked these fields as unused, now it ignores
75 them.
76
77 ### Detection of deprecated identifiers
78
79 {{< check "SA1019" >}} now
80 correctly identifies deprecated methods, in addition to fields and
81 package-level objects. Additionally, staticcheck now keeps track of
82 when each identifier in the Go standard library was deprecated, so
83 that using `-go &lt;version&gt;` can correctly
84 ignore deprecation warnings that don't apply to the targeted Go
85 version.
86
87 ### Other
88
89 - {{< check "SA4017" >}} no longer reports pure functions that are stubs – functions that immediately panic or return a constant.
90 - {{< check "SA5007" >}} no longer flags infinite recursion when the function call is spawned as a new goroutine.
91 - {{< check "SA6002" >}} now recognizes that `unsafe.Pointer` is a pointer type.
92 - {{< check "S1005" >}} no longer suggests `for range` when targeting a version older than Go 1.4.
93 - {{< check "S1026" >}} has been removed. In some rare instances, copying a string is necessary, and all common ways of doing this were incorrectly flagged by the check.
94
95
96 ## Other changes
97
98 - The `-ignore` flag now supports ignoring checks in all packages, by using `*` as the path.
99 - `//line` directives are now being ignored when reporting problems. That is, problems will always be reported for the actual position in the Go files they occur.
100 - From now on, only the first compilation error encountered will be reported.
101 The tools expect to be run on valid Go code and there was little (if any) value in reporting all compilation errors encountered, especially because simple errors can lead to many follow-up errors.
102
103 ## Staticcheck 2017.2.1 Release Notes {#2017.2.1}
104
105 The 2017.2.1 release of the staticcheck suite of tools is the first
106 bug fix release, fixing one bug.
107
108 ### Fixed bugs
109
110 Staticcheck 2017.2 made the detection of deprecated objects
111 Go-version aware. Unfortunately, this only worked correctly for
112 fields and methods, but not package-level objects. This release
113 fixes that.
114
115 ## Staticcheck 2017.2.2 Release Notes {#2017.2.2}
116
117 The 2017.2.2 release of the staticcheck suite of tools is the second
118 bug fix release, fixing several bugs.
119
120 ### Fixed bugs
121
122 - _unused_: correctly apply the NoCopy exemption when using the `-exported` flag.
123 - _keyify_: support external test packages (`package foo_test`)
124 - _staticcheck_: disable {{< check "SA4005" >}} – the check, in its current form, is prone to false positives and will be reimplemented in a future release.