File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ GolangCI-Lint looks for config files in the following paths from the current wor
2828- ` .golangci.json `
2929
3030GolangCI-Lint also searches for config files in all directories from the directory of the first analyzed path up to the root.
31+ If no configuration file has been found, GolangCI-Lint will try to find one in your home directory.
3132To see which config file is being used and where it was sourced from run golangci-lint with ` -v ` option.
3233
3334Config options inside the file are identical to command-line options.
Original file line number Diff line number Diff line change @@ -170,6 +170,7 @@ func (r *FileReader) setupConfigFileSearch() {
170170
171171 // find all dirs from it up to the root
172172 configSearchPaths := []string {"./" }
173+
173174 for {
174175 configSearchPaths = append (configSearchPaths , curDir )
175176 newCurDir := filepath .Dir (curDir )
@@ -179,13 +180,29 @@ func (r *FileReader) setupConfigFileSearch() {
179180 curDir = newCurDir
180181 }
181182
183+ // find home directory for global config
184+ if home , err := homedir .Dir (); err != nil {
185+ r .log .Warnf ("Can't get user's home directory: %s" , err .Error ())
186+ } else if ! sliceContains (configSearchPaths , home ) {
187+ configSearchPaths = append (configSearchPaths , home )
188+ }
189+
182190 r .log .Infof ("Config search paths: %s" , configSearchPaths )
183191 viper .SetConfigName (".golangci" )
184192 for _ , p := range configSearchPaths {
185193 viper .AddConfigPath (p )
186194 }
187195}
188196
197+ func sliceContains (slice []string , value string ) bool {
198+ for _ , v := range slice {
199+ if v == value {
200+ return true
201+ }
202+ }
203+ return false
204+ }
205+
189206var errConfigDisabled = errors .New ("config is disabled by --no-config" )
190207
191208func (r * FileReader ) parseConfigOption () (string , error ) {
You can’t perform that action at this time.
0 commit comments