MCPcopy Create free account
hub / github.com/conventionalcommit/commitlint / LookupConfigPath

Function LookupConfigPath

internal/config.go:44–77  ·  view source on GitHub ↗

LookupConfigPath returns config file path following below order 1. env path 2. commitlint.yaml in current directory 3. use default config

()

Source from the content-addressed store, hash-verified

42// 2. commitlint.yaml in current directory
43// 3. use default config
44func LookupConfigPath() (confPath string, typ ConfigType, err error) {
45 envConf := os.Getenv(CommitlintConfigEnv)
46 if envConf != "" {
47 envConf = filepath.Clean(envConf)
48 isExists, ferr := isFileExists(envConf)
49 if ferr != nil {
50 return "", UnknownConfig, err
51 }
52 if isExists {
53 return envConf, EnvConfig, nil
54 }
55 }
56
57 // get current directory
58 currentDir, err := os.Getwd()
59 if err != nil {
60 return "", UnknownConfig, err
61 }
62
63 // check if conf file exists in current directory
64 for _, confFile := range configFiles {
65 currentDirConf := filepath.Join(currentDir, confFile)
66 isExists, ferr := isFileExists(currentDirConf)
67 if ferr != nil {
68 return "", UnknownConfig, err
69 }
70 if isExists {
71 return currentDirConf, FileConfig, nil
72 }
73 }
74
75 // default config
76 return "", DefaultConfig, nil
77}
78
79func isFileExists(fileName string) (bool, error) {
80 _, err := os.Stat(fileName)

Callers 2

printDebugFunction · 0.92
LookupAndParseFunction · 0.92

Calls 1

isFileExistsFunction · 0.85

Tested by

no test coverage detected