-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrorformat.go
More file actions
35 lines (30 loc) · 798 Bytes
/
errorformat.go
File metadata and controls
35 lines (30 loc) · 798 Bytes
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
//go:generate gopherjs build .
// Main package for https://github.com/gopherjs/gopherjs.
package main
import (
"encoding/json"
"strings"
"github.com/gopherjs/gopherjs/js"
"github.com/reviewdog/errorformat"
)
func main() {
js.Global.Set("errorformat", map[string]interface{}{"Errorformat": Errorformat})
}
// Errorformat returns JSON array of errorformat.Enttry in string or return
// error.
func Errorformat(efms []string, text string) (string, string) {
fmt, err := errorformat.NewErrorformat(efms)
if err != nil {
return "", err.Error()
}
var entries []*errorformat.Entry
s := fmt.NewScanner(strings.NewReader(text))
for s.Scan() {
entries = append(entries, s.Entry())
}
bs, err := json.Marshal(entries)
if err != nil {
return "", err.Error()
}
return string(bs), ""
}