Skip to content

Commit 2f0c327

Browse files
committed
build: fix lint violations
Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
1 parent 176aee0 commit 2f0c327

File tree

3 files changed

+44
-42
lines changed

3 files changed

+44
-42
lines changed

logger.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
)
88

99
// Logger is a unified interface for various logging use cases and practices, including:
10-
// - leveled logging
11-
// - structured logging
10+
// - leveled logging
11+
// - structured logging
1212
type Logger interface {
1313
// Trace logs a Trace event.
1414
//

viper.go

+30-27
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ type DecoderConfigOption func(*mapstructure.DecoderConfig)
132132
// DecodeHook returns a DecoderConfigOption which overrides the default
133133
// DecoderConfig.DecodeHook value, the default is:
134134
//
135-
// mapstructure.ComposeDecodeHookFunc(
136-
// mapstructure.StringToTimeDurationHookFunc(),
137-
// mapstructure.StringToSliceHookFunc(","),
138-
// )
135+
// mapstructure.ComposeDecodeHookFunc(
136+
// mapstructure.StringToTimeDurationHookFunc(),
137+
// mapstructure.StringToSliceHookFunc(","),
138+
// )
139139
func DecodeHook(hook mapstructure.DecodeHookFunc) DecoderConfigOption {
140140
return func(c *mapstructure.DecoderConfig) {
141141
c.DecodeHook = hook
@@ -156,18 +156,18 @@ func DecodeHook(hook mapstructure.DecodeHookFunc) DecoderConfigOption {
156156
//
157157
// For example, if values from the following sources were loaded:
158158
//
159-
// Defaults : {
160-
// "secret": "",
161-
// "user": "default",
162-
// "endpoint": "https://localhost"
163-
// }
164-
// Config : {
165-
// "user": "root"
166-
// "secret": "defaultsecret"
167-
// }
168-
// Env : {
169-
// "secret": "somesecretkey"
170-
// }
159+
// Defaults : {
160+
// "secret": "",
161+
// "user": "default",
162+
// "endpoint": "https://localhost"
163+
// }
164+
// Config : {
165+
// "user": "root"
166+
// "secret": "defaultsecret"
167+
// }
168+
// Env : {
169+
// "secret": "somesecretkey"
170+
// }
171171
//
172172
// The resulting config will have the following values:
173173
//
@@ -785,7 +785,8 @@ func (v *Viper) searchMapWithPathPrefixes(
785785
// isPathShadowedInDeepMap makes sure the given path is not shadowed somewhere
786786
// on its path in the map.
787787
// e.g., if "foo.bar" has a value in the given map, it “shadows”
788-
// "foo.bar.baz" in a lower-priority map
788+
//
789+
// "foo.bar.baz" in a lower-priority map
789790
func (v *Viper) isPathShadowedInDeepMap(path []string, m map[string]interface{}) string {
790791
var parentVal interface{}
791792
for i := 1; i < len(path); i++ {
@@ -810,7 +811,8 @@ func (v *Viper) isPathShadowedInDeepMap(path []string, m map[string]interface{})
810811
// isPathShadowedInFlatMap makes sure the given path is not shadowed somewhere
811812
// in a sub-path of the map.
812813
// e.g., if "foo.bar" has a value in the given map, it “shadows”
813-
// "foo.bar.baz" in a lower-priority map
814+
//
815+
// "foo.bar.baz" in a lower-priority map
814816
func (v *Viper) isPathShadowedInFlatMap(path []string, mi interface{}) string {
815817
// unify input map
816818
var m map[string]interface{}
@@ -835,7 +837,8 @@ func (v *Viper) isPathShadowedInFlatMap(path []string, mi interface{}) string {
835837
// isPathShadowedInAutoEnv makes sure the given path is not shadowed somewhere
836838
// in the environment, when automatic env is on.
837839
// e.g., if "foo.bar" has a value in the environment, it “shadows”
838-
// "foo.bar.baz" in a lower-priority map
840+
//
841+
// "foo.bar.baz" in a lower-priority map
839842
func (v *Viper) isPathShadowedInAutoEnv(path []string) string {
840843
var parentKey string
841844
for i := 1; i < len(path); i++ {
@@ -856,11 +859,11 @@ func (v *Viper) isPathShadowedInAutoEnv(path []string) string {
856859
// would return a string slice for the key if the key's type is inferred by
857860
// the default value and the Get function would return:
858861
//
859-
// []string {"a", "b", "c"}
862+
// []string {"a", "b", "c"}
860863
//
861864
// Otherwise the Get function would return:
862865
//
863-
// "a b c"
866+
// "a b c"
864867
func SetTypeByDefaultValue(enable bool) { v.SetTypeByDefaultValue(enable) }
865868

866869
func (v *Viper) SetTypeByDefaultValue(enable bool) {
@@ -1137,9 +1140,8 @@ func (v *Viper) BindPFlags(flags *pflag.FlagSet) error {
11371140
// BindPFlag binds a specific key to a pflag (as used by cobra).
11381141
// Example (where serverCmd is a Cobra instance):
11391142
//
1140-
// serverCmd.Flags().Int("port", 1138, "Port to run Application server on")
1141-
// Viper.BindPFlag("port", serverCmd.Flags().Lookup("port"))
1142-
//
1143+
// serverCmd.Flags().Int("port", 1138, "Port to run Application server on")
1144+
// Viper.BindPFlag("port", serverCmd.Flags().Lookup("port"))
11431145
func BindPFlag(key string, flag *pflag.Flag) error { return v.BindPFlag(key, flag) }
11441146

11451147
func (v *Viper) BindPFlag(key string, flag *pflag.Flag) error {
@@ -1972,9 +1974,10 @@ func (v *Viper) AllKeys() []string {
19721974

19731975
// flattenAndMergeMap recursively flattens the given map into a map[string]bool
19741976
// of key paths (used as a set, easier to manipulate than a []string):
1975-
// - each path is merged into a single key string, delimited with v.keyDelim
1976-
// - if a path is shadowed by an earlier value in the initial shadow map,
1977-
// it is skipped.
1977+
// - each path is merged into a single key string, delimited with v.keyDelim
1978+
// - if a path is shadowed by an earlier value in the initial shadow map,
1979+
// it is skipped.
1980+
//
19781981
// The resulting set of paths is merged to the given shadow set at the same time.
19791982
func (v *Viper) flattenAndMergeMap(shadow map[string]bool, m map[string]interface{}, prefix string) map[string]bool {
19801983
if shadow != nil && prefix != "" && shadow[prefix] {

viper_test.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"bytes"
1010
"encoding/json"
1111
"io"
12-
"io/ioutil"
1312
"os"
1413
"os/exec"
1514
"path"
@@ -246,7 +245,7 @@ func initDirs(t *testing.T) (string, string, func()) {
246245
testDirs = append(testDirs, `d\d`)
247246
}
248247

249-
root, err := ioutil.TempDir("", "")
248+
root, err := os.MkdirTemp("", "")
250249
require.NoError(t, err, "Failed to create temporary directory")
251250

252251
cleanup := true
@@ -266,7 +265,7 @@ func initDirs(t *testing.T) (string, string, func()) {
266265
err = os.Mkdir(dir, 0o750)
267266
assert.Nil(t, err)
268267

269-
err = ioutil.WriteFile(
268+
err = os.WriteFile(
270269
path.Join(dir, config+".toml"),
271270
[]byte("key = \"value is "+dir+"\"\n"),
272271
0o640)
@@ -998,7 +997,7 @@ func TestBindPFlags(t *testing.T) {
998997
}
999998
}
1000999

1001-
// nolint: dupl
1000+
//nolint:dupl
10021001
func TestBindPFlagsStringSlice(t *testing.T) {
10031002
tests := []struct {
10041003
Expected []string
@@ -1046,7 +1045,7 @@ func TestBindPFlagsStringSlice(t *testing.T) {
10461045
}
10471046
}
10481047

1049-
// nolint: dupl
1048+
//nolint:dupl
10501049
func TestBindPFlagsStringArray(t *testing.T) {
10511050
tests := []struct {
10521051
Expected []string
@@ -1094,7 +1093,7 @@ func TestBindPFlagsStringArray(t *testing.T) {
10941093
}
10951094
}
10961095

1097-
// nolint: dupl
1096+
//nolint:dupl
10981097
func TestBindPFlagsIntSlice(t *testing.T) {
10991098
tests := []struct {
11001099
Expected []int
@@ -1432,7 +1431,7 @@ func TestDirsSearch(t *testing.T) {
14321431
v.SetConfigName(config)
14331432
v.SetDefault(`key`, `default`)
14341433

1435-
entries, err := ioutil.ReadDir(root)
1434+
entries, err := os.ReadDir(root)
14361435
assert.Nil(t, err)
14371436
for _, e := range entries {
14381437
if e.IsDir() {
@@ -2325,10 +2324,10 @@ func doTestCaseInsensitive(t *testing.T, typ, config string) {
23252324
}
23262325

23272326
func newViperWithConfigFile(t *testing.T) (*Viper, string, func()) {
2328-
watchDir, err := ioutil.TempDir("", "")
2327+
watchDir, err := os.MkdirTemp("", "")
23292328
require.Nil(t, err)
23302329
configFile := path.Join(watchDir, "config.yaml")
2331-
err = ioutil.WriteFile(configFile, []byte("foo: bar\n"), 0o640)
2330+
err = os.WriteFile(configFile, []byte("foo: bar\n"), 0o640)
23322331
require.Nil(t, err)
23332332
cleanup := func() {
23342333
os.RemoveAll(watchDir)
@@ -2342,14 +2341,14 @@ func newViperWithConfigFile(t *testing.T) (*Viper, string, func()) {
23422341
}
23432342

23442343
func newViperWithSymlinkedConfigFile(t *testing.T) (*Viper, string, string, func()) {
2345-
watchDir, err := ioutil.TempDir("", "")
2344+
watchDir, err := os.MkdirTemp("", "")
23462345
require.Nil(t, err)
23472346
dataDir1 := path.Join(watchDir, "data1")
23482347
err = os.Mkdir(dataDir1, 0o777)
23492348
require.Nil(t, err)
23502349
realConfigFile := path.Join(dataDir1, "config.yaml")
23512350
t.Logf("Real config file location: %s\n", realConfigFile)
2352-
err = ioutil.WriteFile(realConfigFile, []byte("foo: bar\n"), 0o640)
2351+
err = os.WriteFile(realConfigFile, []byte("foo: bar\n"), 0o640)
23532352
require.Nil(t, err)
23542353
cleanup := func() {
23552354
os.RemoveAll(watchDir)
@@ -2393,7 +2392,7 @@ func TestWatchFile(t *testing.T) {
23932392
})
23942393
v.WatchConfig()
23952394
// when overwriting the file and waiting for the custom change notification handler to be triggered
2396-
err = ioutil.WriteFile(configFile, []byte("foo: baz\n"), 0o640)
2395+
err = os.WriteFile(configFile, []byte("foo: baz\n"), 0o640)
23972396
wg.Wait()
23982397
// then the config value should have changed
23992398
require.Nil(t, err)
@@ -2419,7 +2418,7 @@ func TestWatchFile(t *testing.T) {
24192418
err := os.Mkdir(dataDir2, 0o777)
24202419
require.Nil(t, err)
24212420
configFile2 := path.Join(dataDir2, "config.yaml")
2422-
err = ioutil.WriteFile(configFile2, []byte("foo: baz\n"), 0o640)
2421+
err = os.WriteFile(configFile2, []byte("foo: baz\n"), 0o640)
24232422
require.Nil(t, err)
24242423
// change the symlink using the `ln -sfn` command
24252424
err = exec.Command("ln", "-sfn", dataDir2, path.Join(watchDir, "data")).Run()

0 commit comments

Comments
 (0)