From c4dcd31f68e5d77ce447c0091dd1ca6d7e169807 Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Mon, 9 Oct 2023 17:52:53 +0300 Subject: [PATCH] fix: godot lint issues --- .golangci.yaml | 2 +- file.go | 2 +- flags.go | 2 +- internal/encoding/dotenv/codec_test.go | 6 ++--- internal/encoding/dotenv/map_utils.go | 2 +- internal/encoding/hcl/codec_test.go | 12 +++++----- internal/encoding/ini/codec_test.go | 12 +++++----- internal/encoding/ini/map_utils.go | 2 +- .../encoding/javaproperties/codec_test.go | 6 ++--- internal/encoding/javaproperties/map_utils.go | 2 +- internal/encoding/json/codec_test.go | 4 ++-- internal/encoding/toml/codec_test.go | 6 ++--- internal/encoding/yaml/codec_test.go | 12 +++++----- overrides_test.go | 2 +- util.go | 2 +- viper.go | 24 +++++++++---------- viper_test.go | 4 ++-- 17 files changed, 51 insertions(+), 51 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index acd9eebac..fa28eb3bb 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -22,6 +22,7 @@ linters: - exhaustive - exportloopref - gci + - godot - gofmt - gofumpt - goimports @@ -64,7 +65,6 @@ linters: # - goconst # - gocritic # - gocyclo - # - godot # - gosec # - gosimple # - ifshort diff --git a/file.go b/file.go index 7fc6aff33..a54fe5a7a 100644 --- a/file.go +++ b/file.go @@ -43,7 +43,7 @@ func (v *Viper) searchInPath(in string) (filename string) { return "" } -// Check if file Exists +// exists checks if file exists. func exists(fs afero.Fs, path string) (bool, error) { stat, err := fs.Stat(path) if err == nil { diff --git a/flags.go b/flags.go index ddb4da602..de033ed58 100644 --- a/flags.go +++ b/flags.go @@ -31,7 +31,7 @@ func (p pflagValueSet) VisitAll(fn func(flag FlagValue)) { } // pflagValue is a wrapper around *pflag.flag -// that implements FlagValue +// that implements FlagValue. type pflagValue struct { flag *pflag.Flag } diff --git a/internal/encoding/dotenv/codec_test.go b/internal/encoding/dotenv/codec_test.go index 8a446edb7..ac2257b79 100644 --- a/internal/encoding/dotenv/codec_test.go +++ b/internal/encoding/dotenv/codec_test.go @@ -7,16 +7,16 @@ import ( "github.com/stretchr/testify/require" ) -// original form of the data +// original form of the data. const original = `# key-value pair KEY=value ` -// encoded form of the data +// encoded form of the data. const encoded = `KEY=value ` -// Viper's internal representation +// data is Viper's internal representation. var data = map[string]any{ "KEY": "value", } diff --git a/internal/encoding/dotenv/map_utils.go b/internal/encoding/dotenv/map_utils.go index 1340c7308..4901d7c76 100644 --- a/internal/encoding/dotenv/map_utils.go +++ b/internal/encoding/dotenv/map_utils.go @@ -8,7 +8,7 @@ import ( // flattenAndMergeMap recursively flattens the given map into a new map // Code is based on the function with the same name in the main package. -// TODO: move it to a common place +// TODO: move it to a common place. func flattenAndMergeMap(shadow map[string]any, m map[string]any, prefix string, delimiter string) map[string]any { if shadow != nil && prefix != "" && shadow[prefix] != nil { // prefix is shadowed => nothing more to flatten diff --git a/internal/encoding/hcl/codec_test.go b/internal/encoding/hcl/codec_test.go index 8182c660c..b1d2d5a8a 100644 --- a/internal/encoding/hcl/codec_test.go +++ b/internal/encoding/hcl/codec_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" ) -// original form of the data +// original form of the data. const original = `# key-value pair "key" = "value" @@ -28,7 +28,7 @@ nested map "list" = ["item1", "item2", "item3"] }` -// encoded form of the data +// encoded form of the data. const encoded = `"key" = "value" "list" = ["item1", "item2", "item3"] @@ -43,10 +43,10 @@ const encoded = `"key" = "value" "list" = ["item1", "item2", "item3"] }` -// decoded form of the data +// decoded form of the data. // -// in case of HCL it's slightly different from Viper's internal representation -// (eg. map is decoded into a list of maps) +// In case of HCL it's slightly different from Viper's internal representation +// (e.g. map is decoded into a list of maps). var decoded = map[string]any{ "key": "value", "list": []any{ @@ -75,7 +75,7 @@ var decoded = map[string]any{ }, } -// Viper's internal representation +// data is Viper's internal representation. var data = map[string]any{ "key": "value", "list": []any{ diff --git a/internal/encoding/ini/codec_test.go b/internal/encoding/ini/codec_test.go index 624e0696b..f9d9e7019 100644 --- a/internal/encoding/ini/codec_test.go +++ b/internal/encoding/ini/codec_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" ) -// original form of the data +// original form of the data. const original = `; key-value pair key=value ; key-value pair @@ -17,17 +17,17 @@ key=%(key)s ` -// encoded form of the data +// encoded form of the data. const encoded = `key=value [map] key=value ` -// decoded form of the data +// decoded form of the data. // -// in case of INI it's slightly different from Viper's internal representation -// (eg. top level keys land in a section called default) +// In case of INI it's slightly different from Viper's internal representation +// (e.g. top level keys land in a section called default). var decoded = map[string]any{ "DEFAULT": map[string]any{ "key": "value", @@ -37,7 +37,7 @@ var decoded = map[string]any{ }, } -// Viper's internal representation +// data is Viper's internal representation. var data = map[string]any{ "key": "value", "map": map[string]any{ diff --git a/internal/encoding/ini/map_utils.go b/internal/encoding/ini/map_utils.go index c1919a386..06e703f97 100644 --- a/internal/encoding/ini/map_utils.go +++ b/internal/encoding/ini/map_utils.go @@ -41,7 +41,7 @@ func deepSearch(m map[string]any, path []string) map[string]any { // flattenAndMergeMap recursively flattens the given map into a new map // Code is based on the function with the same name in the main package. -// TODO: move it to a common place +// TODO: move it to a common place. func flattenAndMergeMap(shadow map[string]any, m map[string]any, prefix string, delimiter string) map[string]any { if shadow != nil && prefix != "" && shadow[prefix] != nil { // prefix is shadowed => nothing more to flatten diff --git a/internal/encoding/javaproperties/codec_test.go b/internal/encoding/javaproperties/codec_test.go index 4d521e8f9..ab5aec0b5 100644 --- a/internal/encoding/javaproperties/codec_test.go +++ b/internal/encoding/javaproperties/codec_test.go @@ -7,18 +7,18 @@ import ( "github.com/stretchr/testify/require" ) -// original form of the data +// original form of the data. const original = `#key-value pair key = value map.key = value ` -// encoded form of the data +// encoded form of the data. const encoded = `key = value map.key = value ` -// Viper's internal representation +// data is Viper's internal representation. var data = map[string]any{ "key": "value", "map": map[string]any{ diff --git a/internal/encoding/javaproperties/map_utils.go b/internal/encoding/javaproperties/map_utils.go index 8386920aa..7c7e78a26 100644 --- a/internal/encoding/javaproperties/map_utils.go +++ b/internal/encoding/javaproperties/map_utils.go @@ -41,7 +41,7 @@ func deepSearch(m map[string]any, path []string) map[string]any { // flattenAndMergeMap recursively flattens the given map into a new map // Code is based on the function with the same name in the main package. -// TODO: move it to a common place +// TODO: move it to a common place. func flattenAndMergeMap(shadow map[string]any, m map[string]any, prefix string, delimiter string) map[string]any { if shadow != nil && prefix != "" && shadow[prefix] != nil { // prefix is shadowed => nothing more to flatten diff --git a/internal/encoding/json/codec_test.go b/internal/encoding/json/codec_test.go index 1a05e48e0..87146a1fb 100644 --- a/internal/encoding/json/codec_test.go +++ b/internal/encoding/json/codec_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" ) -// encoded form of the data +// encoded form of the data. const encoded = `{ "key": "value", "list": [ @@ -30,7 +30,7 @@ const encoded = `{ } }` -// Viper's internal representation +// data is Viper's internal representation. var data = map[string]any{ "key": "value", "list": []any{ diff --git a/internal/encoding/toml/codec_test.go b/internal/encoding/toml/codec_test.go index c03f28043..91d9e130c 100644 --- a/internal/encoding/toml/codec_test.go +++ b/internal/encoding/toml/codec_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" ) -// original form of the data +// original form of the data. const original = `# key-value pair key = "value" list = ["item1", "item2", "item3"] @@ -27,7 +27,7 @@ list = [ ] ` -// encoded form of the data +// encoded form of the data. const encoded = `key = 'value' list = ['item1', 'item2', 'item3'] @@ -40,7 +40,7 @@ key = 'value' list = ['item1', 'item2', 'item3'] ` -// Viper's internal representation +// data is Viper's internal representation. var data = map[string]any{ "key": "value", "list": []any{ diff --git a/internal/encoding/yaml/codec_test.go b/internal/encoding/yaml/codec_test.go index 4f998c0db..2d2d8ba6a 100644 --- a/internal/encoding/yaml/codec_test.go +++ b/internal/encoding/yaml/codec_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/require" ) -// original form of the data +// original form of the data. const original = `# key-value pair key: value list: @@ -28,7 +28,7 @@ nested_map: - item3 ` -// encoded form of the data +// encoded form of the data. const encoded = `key: value list: - item1 @@ -45,10 +45,10 @@ nested_map: - item3 ` -// decoded form of the data +// decoded form of the data. // -// in case of YAML it's slightly different from Viper's internal representation -// (eg. map is decoded into a map with interface key) +// In case of YAML it's slightly different from Viper's internal representation +// (e.g. map is decoded into a map with interface key). var decoded = map[string]any{ "key": "value", "list": []any{ @@ -71,7 +71,7 @@ var decoded = map[string]any{ }, } -// Viper's internal representation +// data is Viper's internal representation. var data = map[string]any{ "key": "value", "list": []any{ diff --git a/overrides_test.go b/overrides_test.go index f0de2e90a..a8f4cc17e 100644 --- a/overrides_test.go +++ b/overrides_test.go @@ -126,7 +126,7 @@ func overrideFromLayer(l layer, assert *assert.Assertions, firstPath string, fir } // deepCheckValue checks that all given keys correspond to a valid path in the -// configuration map of the given layer, and that the final value equals the one given +// configuration map of the given layer, and that the final value equals the one given. func deepCheckValue(assert *assert.Assertions, v *Viper, l layer, keys []string, value any) { if assert == nil || v == nil || len(keys) == 0 || len(keys[0]) == 0 { diff --git a/util.go b/util.go index 52116ac44..117c6ac31 100644 --- a/util.go +++ b/util.go @@ -156,7 +156,7 @@ func safeMul(a, b uint) uint { return c } -// parseSizeInBytes converts strings like 1GB or 12 mb into an unsigned integer number of bytes +// parseSizeInBytes converts strings like 1GB or 12 mb into an unsigned integer number of bytes. func parseSizeInBytes(sizeStr string) uint { sizeStr = strings.TrimSpace(sizeStr) lastChar := len(sizeStr) - 1 diff --git a/viper.go b/viper.go index bc631534f..7de2e78e4 100644 --- a/viper.go +++ b/viper.go @@ -77,7 +77,7 @@ type remoteConfigFactory interface { WatchChannel(rp RemoteProvider) (<-chan *RemoteResponse, chan bool) } -// RemoteConfig is optional, see the remote package +// RemoteConfig is optional, see the remote package. var RemoteConfig remoteConfigFactory // UnsupportedConfigError denotes encountering an unsupported @@ -102,7 +102,7 @@ func (str UnsupportedRemoteProviderError) Error() string { // pull the configuration from the remote provider. type RemoteConfigError string -// Error returns the formatted remote provider error +// Error returns the formatted remote provider error. func (rce RemoteConfigError) Error() string { return fmt.Sprintf("Remote Configurations Error: %s", string(rce)) } @@ -126,7 +126,7 @@ func (faee ConfigFileAlreadyExistsError) Error() string { } // A DecoderConfigOption can be passed to viper.Unmarshal to configure -// mapstructure.DecoderConfig options +// mapstructure.DecoderConfig options. type DecoderConfigOption func(*mapstructure.DecoderConfig) // DecodeHook returns a DecoderConfigOption which overrides the default @@ -305,7 +305,7 @@ func Reset() { SupportedRemoteProviders = []string{"etcd", "etcd3", "consul", "firestore", "nats"} } -// TODO: make this lazy initialization instead +// TODO: make this lazy initialization instead. func (v *Viper) resetEncoding() { encoderRegistry := encoding.NewEncoderRegistry() decoderRegistry := encoding.NewDecoderRegistry() @@ -590,7 +590,7 @@ func (v *Viper) AddConfigPath(in string) { // path is the path in the k/v store to retrieve configuration // To retrieve a config file called myapp.json from /configs/myapp.json // you should set path to /configs and set config name (SetConfigName()) to -// "myapp" +// "myapp". func AddRemoteProvider(provider, endpoint, path string) error { return v.AddRemoteProvider(provider, endpoint, path) } @@ -622,8 +622,8 @@ func (v *Viper) AddRemoteProvider(provider, endpoint, path string) error { // path is the path in the k/v store to retrieve configuration // To retrieve a config file called myapp.json from /configs/myapp.json // you should set path to /configs and set config name (SetConfigName()) to -// "myapp" -// Secure Remote Providers are implemented with github.com/bketelsen/crypt +// "myapp". +// Secure Remote Providers are implemented with github.com/bketelsen/crypt. func AddSecureRemoteProvider(provider, endpoint, path, secretkeyring string) error { return v.AddSecureRemoteProvider(provider, endpoint, path, secretkeyring) } @@ -1115,7 +1115,7 @@ func (v *Viper) Unmarshal(rawVal any, opts ...DecoderConfigOption) error { } // defaultDecoderConfig returns default mapstructure.DecoderConfig with support -// of time.Duration values & string slices +// of time.Duration values & string slices. func defaultDecoderConfig(output any, opts ...DecoderConfigOption) *mapstructure.DecoderConfig { c := &mapstructure.DecoderConfig{ Metadata: nil, @@ -1132,7 +1132,7 @@ func defaultDecoderConfig(output any, opts ...DecoderConfigOption) *mapstructure return c } -// A wrapper around mapstructure.Decode that mimics the WeakDecode functionality +// decode is a wrapper around mapstructure.Decode that mimics the WeakDecode functionality. func decode(input any, config *mapstructure.DecoderConfig) error { decoder, err := mapstructure.NewDecoder(config) if err != nil { @@ -1405,7 +1405,7 @@ func readAsCSV(val string) ([]string, error) { } // mostly copied from pflag's implementation of this operation here https://github.com/spf13/pflag/blob/master/string_to_string.go#L79 -// alterations are: errors are swallowed, map[string]any is returned in order to enable cast.ToStringMap +// alterations are: errors are swallowed, map[string]any is returned in order to enable cast.ToStringMap. func stringToStringConv(val string) any { val = strings.Trim(val, "[]") // An empty string would cause an empty map @@ -1429,7 +1429,7 @@ func stringToStringConv(val string) any { } // mostly copied from pflag's implementation of this operation here https://github.com/spf13/pflag/blob/d5e0c0615acee7028e1e2740a11102313be88de1/string_to_int.go#L68 -// alterations are: errors are swallowed, map[string]any is returned in order to enable cast.ToStringMap +// alterations are: errors are swallowed, map[string]any is returned in order to enable cast.ToStringMap. func stringToIntConv(val string) any { val = strings.Trim(val, "[]") // An empty string would cause an empty map @@ -2012,7 +2012,7 @@ func (v *Viper) watchRemoteConfig(provider RemoteProvider) (map[string]any, erro } // AllKeys returns all keys holding a value, regardless of where they are set. -// Nested keys are returned with a v.keyDelim separator +// Nested keys are returned with a v.keyDelim separator. func AllKeys() []string { return v.AllKeys() } func (v *Viper) AllKeys() []string { diff --git a/viper_test.go b/viper_test.go index 6b1b3167a..0e416e7df 100644 --- a/viper_test.go +++ b/viper_test.go @@ -233,7 +233,7 @@ func initIni() { unmarshalReader(r, v.config) } -// make directories for testing +// initDirs makes directories for testing. func initDirs(t *testing.T) (string, string) { var ( testDirs = []string{`a a`, `b`, `C_`} @@ -261,7 +261,7 @@ func initDirs(t *testing.T) (string, string) { return root, config } -// stubs for PFlag Values +// stubs for PFlag Values. type stringValue string func newStringValue(val string, p *string) *stringValue {