Debian Codegraph @

website/content/docs/running-staticcheck/cli/formatters.md

raw
1 ---
2 title: "Formatters"
3 description: "Format Staticcheck's output in different ways"
4 aliases:
5 - /docs/formatters
6 ---
7
8 ## Text {#text}
9
10 _Text_ is the default output formatter.
11 It formats problems using the following format: `file:line:col: message`.
12 This format is commonly used by compilers and linters,
13 and is understood by most editors.
14
15 ### Example output
16 ```text
17 go/src/fmt/print.go:1069:15: this value of afterIndex is never used (SA4006)
18 ```
19
20 ## Stylish {#stylish}
21
22 _Stylish_ is a formatter designed for human consumption.
23 It groups results by file name
24 and breaks up the various pieces of information into columns.
25 Additionally, it displays a final summary.
26
27 This output format is not suited for automatic consumption by tools
28 and may change between versions.
29
30 ```text
31 go/src/fmt/fmt_test.go
32 (43, 2) S1021 should merge variable declaration with assignment on next line
33 (1185, 10) SA9003 empty branch
34
35 go/src/fmt/print.go
36 (77, 18) ST1006 methods on the same type should have the same receiver name (seen 3x "b", 1x "bp")
37 (1069, 15) SA4006 this value of afterIndex is never used
38
39 go/src/fmt/scan.go
40 (465, 5) ST1012 error var complexError should have name of the form errFoo
41 (466, 5) ST1012 error var boolError should have name of the form errFoo
42
43 ✖ 6 problems (6 errors, 0 warnings)
44 ```
45
46 ## JSON {#json}
47
48 The JSON formatter emits one JSON object per problem found –
49 that is, it is a stream of objects, not an array.
50 Most fields should be self-explanatory.
51
52 The `severity` field may be one of
53 `"error"`, `"warning"` or `"ignored"`.
54 Whether a problem is an error or a warning is determined by the `-fail` flag.
55 The value `"ignored"` is used for problems that were ignored,
56 if the `-show-ignored` flag was provided.
57
58 ### Example output
59
60 Note that actual output is not formatted nicely.
61 The example has been formatted to improve readability.
62
63 ```json
64 {
65 "code": "SA4006",
66 "severity": "error",
67 "location": {
68 "file": "/usr/lib/go/src/fmt/print.go",
69 "line": 1082,
70 "column": 15
71 },
72 "end": {
73 "file": "/usr/lib/go/src/fmt/print.go",
74 "line": 1082,
75 "column": 25
76 },
77 "message": "this value of afterIndex is never used"
78 }
79 ```