generated from axetroy/go-cli-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult.go
61 lines (48 loc) · 978 Bytes
/
result.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
package fslint
import "sort"
type LintResult struct {
FilePath string `json:"filepath"`
Expect Mode `json:"expect"`
Level Level `json:"level"`
}
type Results struct {
errCount int
warnCount int
values []LintResult
}
func NewResults() *Results {
return &Results{
values: make([]LintResult, 0),
}
}
func (r *Results) has(result LintResult) bool {
for _, item := range r.values {
if result.FilePath == item.FilePath {
return true
}
}
return false
}
func (r *Results) Append(item LintResult) {
if !r.has(item) {
r.values = append(r.values, item)
switch item.Level {
case LevelError:
r.errCount += 1
case LevelWarn:
r.warnCount += 1
}
}
}
func (r *Results) WarnCount() int {
return r.warnCount
}
func (r *Results) ErrorCount() int {
return r.errCount
}
func (r *Results) Values() []LintResult {
sort.SliceStable(r.values, func(i, j int) bool {
return r.values[i].FilePath < r.values[j].FilePath
})
return r.values
}