@@ -9,8 +9,10 @@ import (
99 "path/filepath"
1010
1111 "golang.org/x/mod/semver"
12- "gopkg.in/yaml.v3"
12+ yaml "gopkg.in/yaml.v3"
1313
14+ "github.com/conventionalcommit/commitlint/internal"
15+ "github.com/conventionalcommit/commitlint/internal/registry"
1416 "github.com/conventionalcommit/commitlint/lint"
1517)
1618
@@ -75,6 +77,7 @@ func getConfigPath(confFilePath string) (confPath string, isDefault bool, retErr
7577
7678// Parse parse given file in confPath, and return Config instance, error if any
7779func Parse (confPath string ) (* lint.Config , error ) {
80+ confPath = filepath .Clean (confPath )
7881 confBytes , err := os .ReadFile (confPath )
7982 if err != nil {
8083 return nil , err
@@ -98,7 +101,7 @@ func Validate(conf *lint.Config) []error {
98101 if conf .Formatter == "" {
99102 errs = append (errs , errors .New ("formatter is empty" ))
100103 } else {
101- _ , ok := globalRegistry .GetFormatter (conf .Formatter )
104+ _ , ok := registry .GetFormatter (conf .Formatter )
102105 if ! ok {
103106 errs = append (errs , fmt .Errorf ("unknown formatter '%s'" , conf .Formatter ))
104107 }
@@ -119,7 +122,7 @@ func Validate(conf *lint.Config) []error {
119122 }
120123
121124 // Check if rule is registered
122- ruleData , ok := globalRegistry .GetRule (ruleName )
125+ ruleData , ok := registry .GetRule (ruleName )
123126 if ! ok {
124127 errs = append (errs , fmt .Errorf ("unknown rule '%s'" , ruleName ))
125128 continue
@@ -135,22 +138,22 @@ func Validate(conf *lint.Config) []error {
135138
136139// WriteToFile util func to write config object to given file
137140func WriteToFile (outFilePath string , conf * lint.Config ) (retErr error ) {
138- file , err := os .Create (outFilePath )
141+ f , err := os .Create (outFilePath )
139142 if err != nil {
140143 return err
141144 }
142145 defer func () {
143- err1 := file .Close ()
144- if retErr == nil && err1 != nil {
145- retErr = err1
146+ err := f .Close ()
147+ if retErr == nil && err != nil {
148+ retErr = err
146149 }
147150 }()
148151
149- w := bufio .NewWriter (file )
152+ w := bufio .NewWriter (f )
150153 defer func () {
151- err1 := w .Flush ()
152- if retErr == nil && err1 != nil {
153- retErr = err1
154+ err := w .Flush ()
155+ if retErr == nil && err != nil {
156+ retErr = err
154157 }
155158 }()
156159
@@ -169,9 +172,9 @@ func checkVersion(versionNo string) error {
169172}
170173
171174func checkIfMinVersion (versionNo string ) error {
172- cmp := semver .Compare (Version (), versionNo )
175+ cmp := semver .Compare (internal . Version (), versionNo )
173176 if cmp != - 1 {
174177 return nil
175178 }
176- return fmt .Errorf ("min version required is %s. you have %s.\n upgrade commitlint" , versionNo , Version ())
179+ return fmt .Errorf ("min version required is %s. you have %s.\n upgrade commitlint" , versionNo , internal . Version ())
177180}
0 commit comments