1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
## errorformat - Vim 'errorformat' implementation in Go
[](https://github.com/reviewdog/errorformat/actions/workflows/tests.yml)
[![codecov][codecov-badge]](https://codecov.io/gh/reviewdog/errorformat)
[](https://goreportcard.com/report/github.com/reviewdog/errorformat)
[](LICENSE)
[](https://pkg.go.dev/github.com/reviewdog/errorformat)
errorformat is Vim's quickfix [errorformat](https://vim-jp.org/vimdoc-en/quickfix.html#error-file-format) implementation in golang.
errorformat provides default errorformats for major tools.
You can see defined errorformats [here](https://godoc.org/github.com/reviewdog/errorformat/fmts).
Also, it's easy to [add new errorformat](fmts/README.md) in a similar way to Vim's errorformat.
Note that it's highly compatible with Vim implementation, but it doesn't support Vim regex.
### :arrow_forward: Playground :arrow_forward:
Try errorformat on [the Playground](https://reviewdog.github.io/errorformat-playground/)!
The playground uses [gopherjs](https://github.com/gopherjs/gopherjs) to try
errorformat implementation in Go with JavaScript :sparkles:
### Usage
```go
import "github.com/reviewdog/errorformat"
```
### Example
#### Code:
```go
in := `
golint.new.go:3:5: exported var V should have comment or be unexported
golint.new.go:5:5: exported var NewError1 should have comment or be unexported
golint.new.go:7:1: comment on exported function F should be of the form "F ..."
golint.new.go:11:1: comment on exported function F2 should be of the form "F2 ..."
`
efm, _ := errorformat.NewErrorformat([]string{`%f:%l:%c: %m`, `%-G%.%#`})
s := efm.NewScanner(strings.NewReader(in))
for s.Scan() {
fmt.Println(s.Entry())
}
```
#### Output:
```
golint.new.go|3 col 5| exported var V should have comment or be unexported
golint.new.go|5 col 5| exported var NewError1 should have comment or be unexported
golint.new.go|7 col 1| comment on exported function F should be of the form "F ..."
golint.new.go|11 col 1| comment on exported function F2 should be of the form "F2 ..."
```
### CLI tool
#### Installation
```
go get -u github.com/reviewdog/errorformat/cmd/errorformat
```
#### Usage
```
Usage: errorformat [flags] [errorformat ...]
errorformat reads compiler/linter/static analyzer result from STDIN, formats
them by given 'errorformat' (90% compatible with Vim's errorformat. :h
errorformat), and outputs formated result to STDOUT.
Example:
$ echo '/path/to/file:14:28: error message\nfile2:3:4: msg' | errorformat "%f:%l:%c: %m"
/path/to/file|14 col 28| error message
file2|3 col 4| msg
$ golint ./... | errorformat -name=golint
The -f flag specifies an alternate format for the entry, using the
syntax of package template. The default output is equivalent to -f
'{{.String}}'. The struct being passed to the template is:
type Entry struct {
// name of a file
Filename string
// line number
Lnum int
// column number (first column is 1)
Col int
// true: "col" is visual column
// false: "col" is byte index
Vcol bool
// error number
Nr int
// search pattern used to locate the error
Pattern string
// description of the error
Text string
// type of the error, 'E', '1', etc.
Type rune
// true: recognized error message
Valid bool
// Original error lines (often one line. more than one line for multi-line
// errorformat. :h errorformat-multi-line)
Lines []string
}
Flags:
-f string
format template for -w=template (default "{{.String}}")
-list
list defined errorformats
-name string
defined errorformat name
-sarif.tool-name string
Tool name for Sarif writer format. Use -name flag if available.
-w string
writer format (template|checkstyle|jsonl|sarif) (default "template")
```
```
$ cat testdata/sbt.in
[warn] /path/to/F1.scala:203: local val in method f is never used: (warning smaple 3)
[warn] val x = 1
[warn] ^
[warn] /path/to/F1.scala:204: local val in method f is never used: (warning smaple 2)
[warn] val x = 2
[warn] ^
[error] /path/to/F2.scala:1093: error: value ++ is not a member of Int
[error] val x = 1 ++ 2
[error] ^
[warn] /path/to/dir/F3.scala:83: local val in method f is never used
[warn] val x = 4
[warn] ^
[error] /path/to/dir/F3.scala:84: error: value ++ is not a member of Int
[error] val x = 5 ++ 2
[error] ^
[warn] /path/to/dir/F3.scala:86: local val in method f is never used
[warn] val x = 6
[warn] ^
$ errorformat "%E[%t%.%+] %f:%l: error: %m" "%A[%t%.%+] %f:%l: %m" "%Z[%.%+] %p^" "%C[%.%+] %.%#" "%-G%.%#" < testdata/sbt.in
/path/to/F1.scala|203 col 13 warning| local val in method f is never used: (warning smaple 3)
/path/to/F1.scala|204 col 7 warning| local val in method f is never used: (warning smaple 2)
/path/to/F2.scala|1093 col 15 error| value ++ is not a member of Int
/path/to/dir/F3.scala|83 col 13 warning| local val in method f is never used
/path/to/dir/F3.scala|84 col 19 error| value ++ is not a member of Int
/path/to/dir/F3.scala|86 col 13 warning| local val in method f is never used
$ cat fmts/testdata/sbt.in | errorformat -name=sbt -w=checkstyle
<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="1.0">
<file name="/home/haya14busa/src/github.com/reviewdog/errorformat/fmts/testdata/resources/scala/scalac.scala">
<error column="3" line="6" message="missing argument list for method error in object Predef" severity="error"></error>
<error column="15" line="4" message="private val in object F is never used" severity="warning"></error>
<error column="15" line="5" message="private method in object F is never used" severity="warning"></error>
</file>
</checkstyle>
$ cat fmts/testdata/sbt.in | errorformat -name=sbt -w=jsonl
{"filename":"/home/haya14busa/src/github.com/reviewdog/errorformat/fmts/testdata/resources/scala/scalac.scala","lnum":6,"col":3,"vcol":true,"nr":0,"pattern":"","text":"missing argument list for method error in object Predef","type":101,"valid":true,"lines":["[error] /home/haya14busa/src/github.com/reviewdog/errorformat/fmts/testdata/resources/scala/scalac.scala:6: missing argument list for method error in object Predef","[error] Unapplied methods are only converted to functions when a function type is expected.","[error] You can make this conversion explicit by writing `error _` or `error(_)` instead of `error`.","[error] error","[error] ^"]}
{"filename":"/home/haya14busa/src/github.com/reviewdog/errorformat/fmts/testdata/resources/scala/scalac.scala","lnum":4,"col":15,"vcol":true,"nr":0,"pattern":"","text":"private val in object F is never used","type":119,"valid":true,"lines":["[warn] /home/haya14busa/src/github.com/reviewdog/errorformat/fmts/testdata/resources/scala/scalac.scala:4: private val in object F is never used","[warn] private val unused = 1","[warn] ^"]}
{"filename":"/home/haya14busa/src/github.com/reviewdog/errorformat/fmts/testdata/resources/scala/scalac.scala","lnum":5,"col":15,"vcol":true,"nr":0,"pattern":"","text":"private method in object F is never used","type":119,"valid":true,"lines":["[warn] /home/haya14busa/src/github.com/reviewdog/errorformat/fmts/testdata/resources/scala/scalac.scala:5: private method in object F is never used","[warn] private def unusedF = {}","[warn] ^"]}
```
### SARIF Support (experimental)
It supports [SARIF](https://sarifweb.azurewebsites.net/) (Static Analysis Results Interchange Format) as output experimentally. Use `-w=sarif` to give it a shot.
<details>
<summary> Example: errorformat -w=sarif</summary>
```shell
$ cat fmts/testdata/sbt.in | errorformat -name=sbt -w=sarif
{
"$schema": "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json",
"runs": [
{
"results": [
{
"level": "error",
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "fmts/testdata/resources/scala/scalac.scala",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startColumn": 3,
"startLine": 6
}
}
}
],
"message": {
"text": "missing argument list for method error in object Predef"
}
},
{
"level": "warning",
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "fmts/testdata/resources/scala/scalac.scala",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startColumn": 15,
"startLine": 4
}
}
}
],
"message": {
"text": "private val in object F is never used"
}
},
{
"level": "warning",
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "fmts/testdata/resources/scala/scalac.scala",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startColumn": 15,
"startLine": 5
}
}
}
],
"message": {
"text": "private method in object F is never used"
}
}
],
"tool": {
"driver": {
"name": "sbt"
}
}
}
],
"version": "2.1.0"
}
```
</details>
### Use cases of 'errorformat' outside Vim
- [reviewdog/reviewdog - A code review dog who keeps your codebase healthy](https://github.com/haya14busa/reviewdog)
- [mattn/efm-langserver - General purpose Language Server](https://github.com/mattn/efm-langserver)
### :bird: Author
haya14busa (https://github.com/haya14busa)
<!-- From https://github.com/zchee/template -->
[travis-badge]: https://img.shields.io/travis/reviewdog/errorformat.svg?style=flat-square&label=%20Travis%20CI&logo=data%3Aimage%2Fsvg%2Bxml%3Bcharset%3Dutf-8%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI2MCIgaGVpZ2h0PSI2MCIgdmlld0JveD0iNSA0IDI0IDI0Ij48cGF0aCBmaWxsPSIjREREIiBkPSJNMTEuMzkyKzkuMzc0aDQuMDk2djEzLjEyaC0xLjUzNnYyLjI0aDYuMDgwdi0yLjQ5NmgtMS45MnYtMTMuMDU2aDQuMzUydjEuOTJoMS45ODR2LTMuOTA0aC0xNS4yOTZ2My45MDRoMi4yNHpNMjkuMjYzKzIuNzE4aC0yNC44NDhjLTAuNDMzKzAtMC44MzIrMC4zMjEtMC44MzIrMC43NDl2MjQuODQ1YzArMC40MjgrMC4zOTgrMC43NzQrMC44MzIrMC43NzRoMjQuODQ4YzAuNDMzKzArMC43NTMtMC4zNDcrMC43NTMtMC43NzR2LTI0Ljg0NWMwLTAuNDI4LTAuMzE5LTAuNzQ5LTAuNzUzLTAuNzQ5ek0yNS43MjgrMTIuMzgyaC00LjU0NHYtMS45MmgtMS43OTJ2MTAuNDk2aDEuOTJ2NS4wNTZoLTguNjR2LTQuOGgxLjUzNnYtMTAuNTZoLTEuNTM2djEuNzI4aC00Ljh2LTYuNDY0aDE3Ljg1NnY2LjQ2NHoiLz48L3N2Zz4=
[circleci-badge]: https://img.shields.io/circleci/project/github/reviewdog/errorformat.svg?style=flat-square&label=%20%20CircleCI&logoWidth=16&logo=data%3Aimage%2Fsvg%2Bxml%3Bcharset%3Dutf-8%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MCIgdmlld0JveD0iMCAwIDIwMCAyMDAiPjxwYXRoIGZpbGw9IiNEREQiIGQ9Ik03NC43IDEwMGMwLTEzLjIgMTAuNy0yMy44IDIzLjgtMjMuOCAxMy4xIDAgMjMuOCAxMC43IDIzLjggMjMuOCAwIDEzLjEtMTAuNyAyMy44LTIzLjggMjMuOC0xMy4xIDAtMjMuOC0xMC43LTIzLjgtMjMuOHpNOTguNSAwQzUxLjggMCAxMi43IDMyIDEuNiA3NS4yYy0uMS4zLS4xLjYtLjEgMSAwIDIuNiAyLjEgNC44IDQuOCA0LjhoNDAuM2MxLjkgMCAzLjYtMS4xIDQuMy0yLjggOC4zLTE4IDI2LjUtMzAuNiA0Ny42LTMwLjYgMjguOSAwIDUyLjQgMjMuNSA1Mi40IDUyLjRzLTIzLjUgNTIuNC01Mi40IDUyLjRjLTIxLjEgMC0zOS4zLTEyLjUtNDcuNi0zMC42LS44LTEuNi0yLjQtMi44LTQuMy0yLjhINi4zYy0yLjYgMC00LjggMi4xLTQuOCA0LjggMCAuMy4xLjYuMSAxQzEyLjYgMTY4IDUxLjggMjAwIDk4LjUgMjAwYzU1LjIgMCAxMDAtNDQuOCAxMDAtMTAwUzE1My43IDAgOTguNSAweiIvPjwvc3ZnPg%3D%3D
[codecov-badge]: https://img.shields.io/codecov/c/github/reviewdog/errorformat.svg?style=flat-square&label=%20%20Codecov%2Eio&logo=data%3Aimage%2Fsvg%2Bxml%3Bcharset%3Dutf-8%3Bbase64%2CPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjA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