spf13 / viper

Go configuration with fangs
MIT License
26.47k stars 2.01k forks source link

fix: gocritic lint issues #1696

Closed alexandear closed 7 months ago

alexandear commented 8 months ago

This PR enables gocritic linter and fixes found lint issues.

The full log of running golangci-lint:

❯ golangci-lint run
internal/encoding/ini/map_utils.go:45:1: paramTypeCombine: func(shadow map[string]any, m map[string]any, prefix string, delimiter string) map[string]any could be replaced with func(shadow, m map[string]any, prefix, delimiter string) map[string]any (gocritic)
func flattenAndMergeMap(shadow map[string]any, m map[string]any, prefix string, delimiter string) map[string]any {
^
internal/encoding/javaproperties/map_utils.go:45:1: paramTypeCombine: func(shadow map[string]any, m map[string]any, prefix string, delimiter string) map[string]any could be replaced with func(shadow, m map[string]any, prefix, delimiter string) map[string]any (gocritic)
func flattenAndMergeMap(shadow map[string]any, m map[string]any, prefix string, delimiter string) map[string]any {
^
internal/encoding/dotenv/map_utils.go:12:1: paramTypeCombine: func(shadow map[string]any, m map[string]any, prefix string, delimiter string) map[string]any could be replaced with func(shadow, m map[string]any, prefix, delimiter string) map[string]any (gocritic)
func flattenAndMergeMap(shadow map[string]any, m map[string]any, prefix string, delimiter string) map[string]any {
^
remote/remote.go:47:1: unnamedResult: consider giving a name to these results (gocritic)
func (rc remoteConfigProvider) WatchChannel(rp viper.RemoteProvider) (<-chan *viper.RemoteResponse, chan bool) {
^
viper.go:960:18: appendAssign: append result not assigned to the same slice (gocritic)
                subv.parents = append(v.parents, strings.ToLower(key))
                               ^
viper.go:1412:5: emptyStringTest: replace `len(val) == 0` with `val == ""` (gocritic)
        if len(val) == 0 {
           ^
viper.go:1436:5: emptyStringTest: replace `len(val) == 0` with `val == ""` (gocritic)
        if len(val) == 0 {
           ^
viper.go:1484:1: paramTypeCombine: func(alias string, key string) could be replaced with func(alias, key string) (gocritic)
func RegisterAlias(alias string, key string) { v.RegisterAlias(alias, key) }
^
viper.go:1486:1: paramTypeCombine: func(alias string, key string) could be replaced with func(alias, key string) (gocritic)
func (v *Viper) RegisterAlias(alias string, key string) {
^
viper.go:1490:1: paramTypeCombine: func(alias string, key string) could be replaced with func(alias, key string) (gocritic)
func (v *Viper) registerAlias(alias string, key string) {
^
overrides_test.go:100:26: emptyStringTest: replace `len(firstKeys[0]) == 0` with `firstKeys[0] == ""` (gocritic)
                len(firstKeys) == 0 || len(firstKeys[0]) == 0 {
                                       ^
overrides_test.go:132:21: emptyStringTest: replace `len(keys[0]) == 0` with `keys[0] == ""` (gocritic)
                len(keys) == 0 || len(keys[0]) == 0 {
                                  ^
overrides_test.go:118:29: emptyStringTest: replace `len(secondKeys[0]) == 0` with `secondKeys[0] == ""` (gocritic)
        if len(secondKeys) == 0 || len(secondKeys[0]) == 0 {
                                   ^
viper_test.go:933:14: evalOrder: may want to evaluate json.Unmarshal([]byte(raw), &m) before the return statement (gocritic)
                        return m, json.Unmarshal([]byte(raw), &m)
                                  ^
viper_test.go:431:12: preferStringWriter: file.WriteString(`key: value`) should be preferred to the file.Write([]byte(`key: value`)) (gocritic)
                _, err = file.Write([]byte(`key: value`))
                         ^
viper_test.go:456:12: preferStringWriter: file.WriteString(`key: value`) should be preferred to the file.Write([]byte(`key: value`)) (gocritic)
                _, err = file.Write([]byte(`key: value`))
                         ^
viper_test.go:2509:1: sloppyTestFuncName: function skipWindows should be of form TestXXX(t *testing.T) (gocritic)
func skipWindows(t *testing.T) {
^
viper_test.go:237:1: unnamedResult: consider giving a name to these results (gocritic)
func initDirs(t *testing.T) (string, string) {
^
viper_test.go:2240:1: unnamedResult: consider giving a name to these results (gocritic)
func newViperWithConfigFile(t *testing.T) (*Viper, string) {
^
viper_test.go:2253:1: unnamedResult: consider giving a name to these results (gocritic)
func newViperWithSymlinkedConfigFile(t *testing.T) (*Viper, string, string) {
^
func (c Codec) Encode(v map[string]any) ([]byte, error) {
      ^
internal/encoding/ini/codec.go:65:7: hugeParam: c is heavy (130 bytes); consider passing it by pointer (gocritic)
func (c Codec) Decode(b []byte, v map[string]any) error {
      ^
internal/encoding/ini/codec.go:93:7: hugeParam: c is heavy (130 bytes); consider passing it by pointer (gocritic)
func (c Codec) keyDelimiter() string {
      ^
logger.go:58:52: hugeParam: _ is heavy (288 bytes); consider passing it by pointer (gocritic)
func (n *discardHandler) Handle(_ context.Context, _ slog.Record) error {
                                                   ^
viper.go:2156:21: hugeParam: in is heavy (114 bytes); consider passing it by pointer (gocritic)
func IniLoadOptions(in ini.LoadOptions) Option {
                    ^
github-actions[bot] commented 8 months ago

πŸ‘‹ Thanks for contributing to Viper! You are awesome! πŸŽ‰

A maintainer will take a look at your pull request shortly. πŸ‘€

In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.

⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9

πŸ“£ If you've already given us your feedback, you can still help by spreading the news, either by sharing the above link or telling people about this on Twitter:

https://twitter.com/sagikazarmark/status/1306904078967074816

Thank you! ❀️

sagikazarmark commented 7 months ago

Thanks!