diff --git a/.golangci.yaml b/.golangci.yaml index c961c472a..1faeae42c 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -13,10 +13,10 @@ linters-settings: - diagnostic - experimental - opinionated - - performance - style disabled-checks: - importShadow + - unnamedResult golint: min-confidence: 0 goimports: diff --git a/internal/encoding/ini/codec.go b/internal/encoding/ini/codec.go index 597f74426..d91cf59d2 100644 --- a/internal/encoding/ini/codec.go +++ b/internal/encoding/ini/codec.go @@ -19,7 +19,7 @@ type Codec struct { LoadOptions LoadOptions } -func (c *Codec) Encode(v map[string]any) ([]byte, error) { +func (c Codec) Encode(v map[string]any) ([]byte, error) { cfg := ini.Empty() ini.PrettyFormat = false @@ -62,7 +62,7 @@ func (c *Codec) Encode(v map[string]any) ([]byte, error) { return buf.Bytes(), nil } -func (c *Codec) Decode(b []byte, v map[string]any) error { +func (c Codec) Decode(b []byte, v map[string]any) error { cfg := ini.Empty(c.LoadOptions) err := cfg.Append(b) @@ -90,7 +90,7 @@ func (c *Codec) Decode(b []byte, v map[string]any) error { return nil } -func (c *Codec) keyDelimiter() string { +func (c Codec) keyDelimiter() string { if c.KeyDelimiter == "" { return "." } diff --git a/logger.go b/logger.go index c25c7a019..8938053b3 100644 --- a/logger.go +++ b/logger.go @@ -55,7 +55,6 @@ func (n *discardHandler) Enabled(_ context.Context, _ slog.Level) bool { return false } -//nolint:gocritic // hugeParam: _ is heavy (288 bytes); consider passing it by pointer func (n *discardHandler) Handle(_ context.Context, _ slog.Record) error { return nil } diff --git a/remote/remote.go b/remote/remote.go index 4a89e4272..d61f88046 100644 --- a/remote/remote.go +++ b/remote/remote.go @@ -44,7 +44,7 @@ func (rc remoteConfigProvider) Watch(rp viper.RemoteProvider) (io.Reader, error) return bytes.NewReader(resp), nil } -func (rc remoteConfigProvider) WatchChannel(rp viper.RemoteProvider) (responseCh <-chan *viper.RemoteResponse, quitCh chan bool) { +func (rc remoteConfigProvider) WatchChannel(rp viper.RemoteProvider) (<-chan *viper.RemoteResponse, chan bool) { cm, err := getConfigManager(rp) if err != nil { return nil, nil diff --git a/viper.go b/viper.go index 4bff7e831..7f54c265a 100644 --- a/viper.go +++ b/viper.go @@ -345,7 +345,7 @@ func (v *Viper) resetEncoding() { } { - codec := &ini.Codec{ + codec := ini.Codec{ KeyDelimiter: v.keyDelim, LoadOptions: v.iniLoadOptions, } @@ -2182,8 +2182,6 @@ func (v *Viper) SetConfigPermissions(perm os.FileMode) { } // IniLoadOptions sets the load options for ini parsing. -// -//nolint:gocritic // hugeParam: in is heavy (114 bytes); consider passing it by pointer func IniLoadOptions(in ini.LoadOptions) Option { return optionFunc(func(v *Viper) { v.iniLoadOptions = in diff --git a/viper_test.go b/viper_test.go index 0d7e6f3bd..2dd67a189 100644 --- a/viper_test.go +++ b/viper_test.go @@ -234,15 +234,17 @@ func initIni() { } // initDirs makes directories for testing. -func initDirs(t *testing.T) (root, config string) { - testDirs := []string{`a a`, `b`, `C_`} - config = `improbable` +func initDirs(t *testing.T) (string, string) { + var ( + testDirs = []string{`a a`, `b`, `C_`} + config = `improbable` + ) if runtime.GOOS != "windows" { testDirs = append(testDirs, `d\d`) } - root = t.TempDir() + root := t.TempDir() for _, dir := range testDirs { innerDir := filepath.Join(root, dir) @@ -2342,12 +2344,12 @@ func doTestCaseInsensitive(t *testing.T, typ, config string) { assert.Equal(t, 5, cast.ToInt(Get("ef.lm.p.q"))) } -func newViperWithConfigFile(t *testing.T) (v *Viper, configFile string) { +func newViperWithConfigFile(t *testing.T) (*Viper, string) { watchDir := t.TempDir() - configFile = path.Join(watchDir, "config.yaml") + configFile := path.Join(watchDir, "config.yaml") err := os.WriteFile(configFile, []byte("foo: bar\n"), 0o640) require.NoError(t, err) - v = New() + v := New() v.SetConfigFile(configFile) err = v.ReadInConfig() require.NoError(t, err) @@ -2355,8 +2357,8 @@ func newViperWithConfigFile(t *testing.T) (v *Viper, configFile string) { return v, configFile } -func newViperWithSymlinkedConfigFile(t *testing.T) (v *Viper, watchDir, configFile string) { - watchDir = t.TempDir() +func newViperWithSymlinkedConfigFile(t *testing.T) (*Viper, string, string) { + watchDir := t.TempDir() dataDir1 := path.Join(watchDir, "data1") err := os.Mkdir(dataDir1, 0o777) require.NoError(t, err) @@ -2367,11 +2369,11 @@ func newViperWithSymlinkedConfigFile(t *testing.T) (v *Viper, watchDir, configFi // now, symlink the tm `data1` dir to `data` in the baseDir os.Symlink(dataDir1, path.Join(watchDir, "data")) // and link the `/datadir1/config.yaml` to `/config.yaml` - configFile = path.Join(watchDir, "config.yaml") + configFile := path.Join(watchDir, "config.yaml") os.Symlink(path.Join(watchDir, "data", "config.yaml"), configFile) t.Logf("Config file location: %s\n", path.Join(watchDir, "config.yaml")) // init Viper - v = New() + v := New() v.SetConfigFile(configFile) err = v.ReadInConfig() require.NoError(t, err)