Add home directory to config file search paths (#1325)
This commit is contained in:
parent
a35fd6e91a
commit
13c2a34028
@ -28,6 +28,7 @@ GolangCI-Lint looks for config files in the following paths from the current wor
|
|||||||
- `.golangci.json`
|
- `.golangci.json`
|
||||||
|
|
||||||
GolangCI-Lint also searches for config files in all directories from the directory of the first analyzed path up to the root.
|
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.
|
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.
|
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
|
// find all dirs from it up to the root
|
||||||
configSearchPaths := []string{"./"}
|
configSearchPaths := []string{"./"}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
configSearchPaths = append(configSearchPaths, curDir)
|
configSearchPaths = append(configSearchPaths, curDir)
|
||||||
newCurDir := filepath.Dir(curDir)
|
newCurDir := filepath.Dir(curDir)
|
||||||
@ -179,6 +180,13 @@ func (r *FileReader) setupConfigFileSearch() {
|
|||||||
curDir = newCurDir
|
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)
|
r.log.Infof("Config search paths: %s", configSearchPaths)
|
||||||
viper.SetConfigName(".golangci")
|
viper.SetConfigName(".golangci")
|
||||||
for _, p := range configSearchPaths {
|
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")
|
var errConfigDisabled = errors.New("config is disabled by --no-config")
|
||||||
|
|
||||||
func (r *FileReader) parseConfigOption() (string, error) {
|
func (r *FileReader) parseConfigOption() (string, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user