/
conf.go
39 lines (35 loc) 路 941 Bytes
/
conf.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
// Package project provides utility for reviewdog execution based on project
// config.
package project
import "gopkg.in/yaml.v3"
// Config represents reviewdog config.
type Config struct {
Runner map[string]*Runner
}
// Runner represents config for a runner.
type Runner struct {
// Runner command. (e.g. `golint ./...`)
Cmd string
// tool name in review comment. (e.g. `golint`)
Name string
// errorformat name. (e.g. `checkstyle`)
Format string
// errorformat. (e.g. `%f:%l:%c:%m`, `%-G%.%#`)
Errorformat []string
// Report Level for this runner. ("info", "warning", "error")
Level string
}
// Parse parses reviewdog config in yaml format.
func Parse(yml []byte) (*Config, error) {
out := &Config{}
if err := yaml.Unmarshal(yml, out); err != nil {
return nil, err
}
// Insert `Name` field if it's empty.
for name, runner := range out.Runner {
if runner.Name == "" {
runner.Name = name
}
}
return out, nil
}