-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.go
74 lines (58 loc) · 1.15 KB
/
parser.go
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
package main
import (
"errors"
"fmt"
"regexp"
"strconv"
"strings"
)
var reg = regexp.MustCompile("([^:]+):(\\d*):(\\d*?):(\\w+): (.+) .*\\((\\w+)\\)")
type lintResult struct {
path string
line int
column int
level string
message string
linter string
code string
}
func (l *lintResult) format() string {
s := fmt.Sprintf("`%s` - %s:%d:%d - *%s* - %s\n", l.level, l.path, l.line, l.column, l.message, l.linter)
return s
}
func (l *lintResult) extractCode() {
l.code = extract(l.path, l.line)
}
func newLintResult(a []string) (*lintResult, error) {
if len(a) < 2 {
return nil, errors.New("Not a valid slice")
}
line, err := strconv.Atoi(a[1])
if err != nil {
line = 0
}
column, err := strconv.Atoi(a[2])
if err != nil {
column = 0
}
l := &lintResult{
path: a[0],
line: line,
column: column,
level: a[3],
message: a[4],
linter: a[5],
}
return l, nil
}
func parseResult(out string) []string {
return strings.Split(out, "\n")
}
func parseLine(line string) (*lintResult, error) {
l := reg.FindAllStringSubmatch(line, -1)
if len(l) > 0 {
a := l[0]
return newLintResult(a[1:])
}
return nil, nil
}