github.com/friedemannf/reviewdog@v0.14.0/project/conf.go (about)

     1  // Package project provides utility for reviewdog execution based on project
     2  // config.
     3  package project
     4  
     5  import "gopkg.in/yaml.v2"
     6  
     7  // Config represents reviewdog config.
     8  type Config struct {
     9  	Runner map[string]*Runner
    10  }
    11  
    12  // Runner represents config for a runner.
    13  type Runner struct {
    14  	// Runner command. (e.g. `golint ./...`)
    15  	Cmd string
    16  	// tool name in review comment. (e.g. `golint`)
    17  	Name string
    18  	// errorformat name. (e.g. `checkstyle`)
    19  	Format string
    20  	// errorformat. (e.g. `%f:%l:%c:%m`, `%-G%.%#`)
    21  	Errorformat []string
    22  	// Report Level for this runner. ("info", "warning", "error")
    23  	Level string
    24  }
    25  
    26  // Parse parses reviewdog config in yaml format.
    27  func Parse(yml []byte) (*Config, error) {
    28  	out := &Config{}
    29  	if err := yaml.Unmarshal(yml, out); err != nil {
    30  		return nil, err
    31  	}
    32  	// Insert `Name` field if it's empty.
    33  	for name, runner := range out.Runner {
    34  		if runner.Name == "" {
    35  			runner.Name = name
    36  		}
    37  	}
    38  	return out, nil
    39  }