Validate validates given config instance, it checks the following If formatters, rules are registered/known If arguments to rules are valid If version is valid and at least minimum than commitlint version used
(conf *lint.Config)
| 68 | // If arguments to rules are valid |
| 69 | // If version is valid and at least minimum than commitlint version used |
| 70 | func Validate(conf *lint.Config) []error { |
| 71 | var errs []error |
| 72 | |
| 73 | err := isValidVersion(conf.MinVersion) |
| 74 | if err != nil { |
| 75 | errs = append(errs, err) |
| 76 | } |
| 77 | |
| 78 | if conf.Formatter == "" { |
| 79 | errs = append(errs, errors.New("formatter is empty")) |
| 80 | } else { |
| 81 | _, ok := registry.GetFormatter(conf.Formatter) |
| 82 | if !ok { |
| 83 | errs = append(errs, fmt.Errorf("unknown formatter '%s'", conf.Formatter)) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // Check Severity Level |
| 88 | if !isSeverityValid(conf.Severity.Default) { |
| 89 | errs = append(errs, fmt.Errorf("unknown default severity level '%s'", conf.Severity.Default)) |
| 90 | } |
| 91 | |
| 92 | for ruleName, sev := range conf.Severity.Rules { |
| 93 | // Check Severity Level of rule config |
| 94 | if !isSeverityValid(sev) { |
| 95 | errs = append(errs, fmt.Errorf("unknown severity level '%s' for rule '%s'", sev, ruleName)) |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | for _, ruleName := range conf.Rules { |
| 100 | // Check if rule is registered |
| 101 | _, ok := registry.GetRule(ruleName) |
| 102 | if !ok { |
| 103 | errs = append(errs, fmt.Errorf("unknown rule '%s'", ruleName)) |
| 104 | continue |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // Check for duplicate rules |
| 109 | ruleSeen := make(map[string]struct{}, len(conf.Rules)) |
| 110 | for _, ruleName := range conf.Rules { |
| 111 | if _, exists := ruleSeen[ruleName]; exists { |
| 112 | errs = append(errs, fmt.Errorf("duplicate rule '%s' in rules list", ruleName)) |
| 113 | } else { |
| 114 | ruleSeen[ruleName] = struct{}{} |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | for ruleName, ruleSetting := range conf.Settings { |
| 119 | // Check if rule is registered |
| 120 | ruleData, ok := registry.GetRule(ruleName) |
| 121 | if !ok { |
| 122 | errs = append(errs, fmt.Errorf("unknown rule '%s'", ruleName)) |
| 123 | continue |
| 124 | } |
| 125 | |
| 126 | err := ruleData.Apply(ruleSetting) |
| 127 | if err != nil { |