Add home directory to config file search paths ()

This commit is contained in:
SystemGlitch 2020-08-24 08:44:33 +02:00 committed by GitHub
parent a35fd6e91a
commit 13c2a34028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions
docs/src/docs/usage
pkg/config

@ -28,6 +28,7 @@ GolangCI-Lint looks for config files in the following paths from the current wor
- `.golangci.json`
GolangCI-Lint also searches for config files in all directories from the directory of the first analyzed path up to the root.
If no configuration file has been found, GolangCI-Lint will try to find one in your home directory.
To see which config file is being used and where it was sourced from run golangci-lint with `-v` option.
Config options inside the file are identical to command-line options.

@ -170,6 +170,7 @@ func (r *FileReader) setupConfigFileSearch() {
// find all dirs from it up to the root
configSearchPaths := []string{"./"}
for {
configSearchPaths = append(configSearchPaths, curDir)
newCurDir := filepath.Dir(curDir)
@ -179,6 +180,13 @@ func (r *FileReader) setupConfigFileSearch() {
curDir = newCurDir
}
// find home directory for global config
if home, err := homedir.Dir(); err != nil {
r.log.Warnf("Can't get user's home directory: %s", err.Error())
} else if !sliceContains(configSearchPaths, home) {
configSearchPaths = append(configSearchPaths, home)
}
r.log.Infof("Config search paths: %s", configSearchPaths)
viper.SetConfigName(".golangci")
for _, p := range configSearchPaths {
@ -186,6 +194,15 @@ func (r *FileReader) setupConfigFileSearch() {
}
}
func sliceContains(slice []string, value string) bool {
for _, v := range slice {
if v == value {
return true
}
}
return false
}
var errConfigDisabled = errors.New("config is disabled by --no-config")
func (r *FileReader) parseConfigOption() (string, error) {