@@ -16,15 +16,6 @@ import (
1616 "github.com/conventionalcommit/commitlint/lint"
1717)
1818
19- const commitlintConfig = "COMMITLINT_CONFIG"
20-
21- var configFiles = []string {
22- ".commitlint.yml" ,
23- ".commitlint.yaml" ,
24- "commitlint.yml" ,
25- "commitlint.yaml" ,
26- }
27-
2819// Parse parse given file in confPath, and return Config instance, error if any
2920func Parse (confPath string ) (* lint.Config , error ) {
3021 confPath = filepath .Clean (confPath )
@@ -97,12 +88,12 @@ func Validate(conf *lint.Config) []error {
9788// LookupAndParse gets the config path according to the precedence
9889// if exists, parses the config file and returns config instance
9990func LookupAndParse () (* lint.Config , error ) {
100- confFilePath , useDefault , err := lookupConfigPath ()
91+ confFilePath , confType , err := internal . LookupConfigPath ()
10192 if err != nil {
10293 return nil , err
10394 }
10495
105- if useDefault {
96+ if confType == internal . DefaultConfig {
10697 return defConf , nil
10798 }
10899
@@ -113,39 +104,9 @@ func LookupAndParse() (*lint.Config, error) {
113104 return conf , nil
114105}
115106
116- // lookupConfigPath returns config file path following below order
117- // 1. env path
118- // 2. commitlint.yaml in current directory
119- // 3. use default config
120- func lookupConfigPath () (confPath string , isDefault bool , retErr error ) {
121- envConf := os .Getenv (commitlintConfig )
122- if envConf != "" {
123- envConf = filepath .Clean (envConf )
124- if _ , err1 := os .Stat (envConf ); ! os .IsNotExist (err1 ) {
125- return envConf , false , nil
126- }
127- }
128-
129- // get current directory
130- currentDir , err := os .Getwd ()
131- if err != nil {
132- return "" , false , err
133- }
134-
135- // check if conf file exists in current directory
136- for _ , confFile := range configFiles {
137- currentDirConf := filepath .Join (currentDir , confFile )
138- if _ , err1 := os .Stat (currentDirConf ); ! os .IsNotExist (err1 ) {
139- return currentDirConf , false , nil
140- }
141- }
142-
143- // default config
144- return "" , true , nil
145- }
146-
147107// WriteToFile util func to write config object to given file
148108func WriteToFile (outFilePath string , conf * lint.Config ) (retErr error ) {
109+ outFilePath = filepath .Clean (outFilePath )
149110 f , err := os .Create (outFilePath )
150111 if err != nil {
151112 return err
0 commit comments