cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
internal/config/annotation.go
36lines · modecode
| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "regexp" |
| 5 | |
| 6 | "github.com/cloudflare/pint/internal/checks" |
| 7 | ) |
| 8 | |
| 9 | type AnnotationSettings struct { |
| 10 | Key string `hcl:",label"` |
| 11 | Value string `hcl:"value,optional"` |
| 12 | Required bool `hcl:"required,optional"` |
| 13 | Severity string `hcl:"severity,optional"` |
| 14 | } |
| 15 | |
| 16 | func (as AnnotationSettings) validate() error { |
| 17 | if as.Severity != "" { |
| 18 | if _, err := checks.ParseSeverity(as.Severity); err != nil { |
| 19 | return err |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | if _, err := regexp.Compile(as.Value); err != nil { |
| 24 | return err |
| 25 | } |
| 26 | |
| 27 | return nil |
| 28 | } |
| 29 | |
| 30 | func (as AnnotationSettings) getSeverity(fallback checks.Severity) checks.Severity { |
| 31 | if as.Severity != "" { |
| 32 | sev, _ := checks.ParseSeverity(as.Severity) |
| 33 | return sev |
| 34 | } |
| 35 | return fallback |
| 36 | } |
| 37 | |