Skip to content

Commit 0bae4c3

Browse files
feat(lint): add version in lint config
1 parent 140a419 commit 0bae4c3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

config/config.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"path/filepath"
1010

11+
"golang.org/x/mod/semver"
1112
"gopkg.in/yaml.v3"
1213

1314
"github.com/conventionalcommit/commitlint/lint"
@@ -38,6 +39,11 @@ func GetConfig(confPath string) (*lint.Config, error) {
3839
if conf.Formatter == "" {
3940
return nil, errors.New("conf error: formatter is empty")
4041
}
42+
43+
err = checkVersion(conf.Version)
44+
if err != nil {
45+
return nil, err
46+
}
4147
return conf, nil
4248
}
4349

@@ -95,6 +101,11 @@ func Validate(conf *lint.Config) []error {
95101
}
96102
}
97103

104+
err := checkVersion(conf.Version)
105+
if err != nil {
106+
errs = append(errs, err)
107+
}
108+
98109
for ruleName, r := range conf.Rules {
99110
// Check Severity Level of rule config
100111
switch r.Severity {
@@ -143,3 +154,13 @@ func WriteConfToFile(outFilePath string, conf *lint.Config) (retErr error) {
143154
enc := yaml.NewEncoder(w)
144155
return enc.Encode(conf)
145156
}
157+
158+
func checkVersion(verInfo string) error {
159+
if verInfo == "" {
160+
return errors.New("version is empty")
161+
}
162+
if !semver.IsValid(verInfo) {
163+
return errors.New("invalid version should be in semver format")
164+
}
165+
return nil
166+
}

lint/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ type RuleConfig struct {
1414

1515
// Config represent linter config
1616
type Config struct {
17+
// Version is the minimum version required
18+
// should be in semver format
19+
Version string `yaml:"version"`
20+
1721
// Formatter of the lint result
1822
Formatter string `yaml:"formatter"`
1923

0 commit comments

Comments
 (0)