Repository: spf13/viper
Pull request #807 (2019-12-06 11:59:32)

Fix linters


Patch:
diff --git a/.golangci.yml b/.golangci.yml
index bd0ded4..0ea9249 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -11,16 +11,8 @@ linters:
         - maligned
 
         # TODO: fix me
-        - gofmt
-        - goimports
-        - whitespace
-        - deadcode
-        - unused
         - wsl
-        - golint
-        - stylecheck
         - gochecknoinits
-        - misspell
         - gosimple
         - gochecknoglobals
         - errcheck
diff --git a/Makefile b/Makefile
index 048280e..e39b8b5 100644
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,7 @@ clear: ## Clear the working area and the project
 	rm -rf bin/
 
 .PHONY: check
-check: lint ## Run tests and linters
+check: test lint ## Run tests and linters
 
 bin/gotestsum: bin/gotestsum-${GOTESTSUM_VERSION}
 	@ln -sf gotestsum-${GOTESTSUM_VERSION} bin/gotestsum
diff --git a/remote/remote.go b/remote/remote.go
index 02cf5a9..6e8a534 100644
--- a/remote/remote.go
+++ b/remote/remote.go
@@ -12,6 +12,7 @@ import (
 	"os"
 
 	"github.com/spf13/viper"
+
 	crypt "github.com/xordataexchange/crypt/config"
 )
 
@@ -63,9 +64,7 @@ func (rc remoteConfigProvider) WatchChannel(rp viper.RemoteProvider) (<-chan *vi
 					Error: resp.Error,
 					Value: resp.Value,
 				}
-
 			}
-
 		}
 	}(cryptoResponseCh, viperResponsCh, quitwc, quit)
 
diff --git a/viper.go b/viper.go
index 6014bf7..a944cde 100644
--- a/viper.go
+++ b/viper.go
@@ -970,7 +970,7 @@ func BindEnv(input ...string) error { return v.BindEnv(input...) }
 func (v *Viper) BindEnv(input ...string) error {
 	var key, envkey string
 	if len(input) == 0 {
-		return fmt.Errorf("BindEnv missing key to bind to")
+		return fmt.Errorf("missing key to bind to")
 	}
 
 	key = strings.ToLower(input[0])
@@ -996,7 +996,6 @@ func (v *Viper) BindEnv(input ...string) error {
 //
 // Note: this assumes a lower-cased key given.
 func (v *Viper) find(lcaseKey string, flagDefault bool) interface{} {
-
 	var (
 		val    interface{}
 		exists bool
@@ -1348,7 +1347,7 @@ func (v *Viper) WriteConfig() error {
 func SafeWriteConfig() error { return v.SafeWriteConfig() }
 func (v *Viper) SafeWriteConfig() error {
 	if len(v.configPaths) < 1 {
-		return errors.New("Missing configuration for 'configPath'")
+		return errors.New("missing configuration for 'configPath'")
 	}
 	return v.SafeWriteConfigAs(filepath.Join(v.configPaths[0], v.configName+"."+v.configType))
 }
@@ -1369,12 +1368,11 @@ func (v *Viper) SafeWriteConfigAs(filename string) error {
 	return v.writeConfig(filename, false)
 }
 
-func writeConfig(filename string, force bool) error { return v.writeConfig(filename, force) }
 func (v *Viper) writeConfig(filename string, force bool) error {
 	jww.INFO.Println("Attempting to write configuration to file.")
 	ext := filepath.Ext(filename)
 	if len(ext) <= 1 {
-		return fmt.Errorf("Filename: %s requires valid extension.", filename)
+		return fmt.Errorf("filename: %s requires valid extension", filename)
 	}
 	configType := ext[1:]
 	if !stringInSlice(configType, SupportedExts) {
@@ -1487,9 +1485,6 @@ func (v *Viper) unmarshalReader(in io.Reader, c map[string]interface{}) error {
 }
 
 // Marshal a map into Writer.
-func marshalWriter(f afero.File, configType string) error {
-	return v.marshalWriter(f, configType)
-}
 func (v *Viper) marshalWriter(f afero.File, configType string) error {
 	c := v.AllSettings()
 	switch configType {


Test patch:
diff --git a/viper_test.go b/viper_test.go
index f8349ac..c1cf557 100644
--- a/viper_test.go
+++ b/viper_test.go
@@ -128,7 +128,7 @@ IMPORT_PATH = gopkg.in/%(NAME)s.%(VERSION)s
 # Information about package author
 # Bio can be written in multiple lines.
 [author]
-NAME   = Unknwon  ; Succeeding comment
+NAME   = Unknown  ; Succeeding comment
 E-MAIL = fake@localhost
 GITHUB = https://github.com/%(NAME)s
 BIO    = """Gopher.
@@ -236,7 +236,6 @@ func initIni() {
 
 // make directories for testing
 func initDirs(t *testing.T) (string, string, func()) {
-
 	var (
 		testDirs = []string{`a a`, `b`, `C_`}
 		config   = `improbable`
@@ -463,7 +462,6 @@ func TestEnv(t *testing.T) {
 	AutomaticEnv()
 
 	assert.Equal(t, "crunk", Get("name"))
-
 }
 
 func TestEmptyEnv(t *testing.T) {
@@ -600,8 +598,8 @@ func TestAllKeys(t *testing.T) {
 		"title": "TOML Example",
 		"author": map[string]interface{}{
 			"e-mail": "fake@localhost",
-			"github": "https://github.com/Unknwon",
-			"name":   "Unknwon",
+			"github": "https://github.com/Unknown",
+			"name":   "Unknown",
 			"bio":    "Gopher.\nCoding addict.\nGood man.\n",
 		},
 		"ppu":  0.55,
@@ -812,7 +810,6 @@ func TestBindPFlags(t *testing.T) {
 	for name, expected := range mutatedTestValues {
 		assert.Equal(t, expected, v.Get(name))
 	}
-
 }
 
 func TestBindPFlagsStringSlice(t *testing.T) {
@@ -924,7 +921,6 @@ func TestBindPFlag(t *testing.T) {
 	flag.Changed = true // hack for pflag usage
 
 	assert.Equal(t, "testing_mutate", Get("testvalue"))
-
 }
 
 func TestBoundCaseSensitivity(t *testing.T) {
@@ -946,7 +942,6 @@ func TestBoundCaseSensitivity(t *testing.T) {
 
 	BindPFlag("eYEs", flag)
 	assert.Equal(t, "green", Get("eyes"))
-
 }
 
 func TestSizeInBytes(t *testing.T) {
@@ -1049,18 +1044,18 @@ func TestFindsNestedKeys(t *testing.T) {
 		"owner.dob":           dob,
 		"beard":               true,
 		"foos": []map[string]interface{}{
-			map[string]interface{}{
+			{
 				"foo": []map[string]interface{}{
-					map[string]interface{}{
+					{
 						"key": 1,
 					},
-					map[string]interface{}{
+					{
 						"key": 2,
 					},
-					map[string]interface{}{
+					{
 						"key": 3,
 					},
-					map[string]interface{}{
+					{
 						"key": 4,
 					},
 				},
@@ -1069,10 +1064,8 @@ func TestFindsNestedKeys(t *testing.T) {
 	}
 
 	for key, expectedValue := range expected {
-
 		assert.Equal(t, expectedValue, v.Get(key))
 	}
-
 }
 
 func TestReadBufConfig(t *testing.T) {
@@ -1136,7 +1129,6 @@ func TestIsSet(t *testing.T) {
 }
 
 func TestDirsSearch(t *testing.T) {
-
 	root, config, cleanup := initDirs(t)
 	defer cleanup()
 
@@ -1159,7 +1151,6 @@ func TestDirsSearch(t *testing.T) {
 }
 
 func TestWrongDirsSearchNotFound(t *testing.T) {
-
 	_, config, cleanup := initDirs(t)
 	defer cleanup()
 
@@ -1179,7 +1170,6 @@ func TestWrongDirsSearchNotFound(t *testing.T) {
 }
 
 func TestWrongDirsSearchNotFoundForMerge(t *testing.T) {
-
 	_, config, cleanup := initDirs(t)
 	defer cleanup()
 
@@ -1457,7 +1447,7 @@ func TestSafeWriteConfigWithMissingConfigPath(t *testing.T) {
 	v.SetFs(fs)
 	v.SetConfigName("c")
 	v.SetConfigType("yaml")
-	require.EqualError(t, v.SafeWriteConfig(), "Missing configuration for 'configPath'")
+	require.EqualError(t, v.SafeWriteConfig(), "missing configuration for 'configPath'")
 }
 
 func TestSafeWriteConfigWithExistingFile(t *testing.T) {
@@ -1679,7 +1669,6 @@ func TestMergeConfigMap(t *testing.T) {
 	}
 
 	assert(1234)
-
 }
 
 func TestUnmarshalingWithAliases(t *testing.T) {
@@ -1718,7 +1707,6 @@ func TestSetConfigNameClearsFileCache(t *testing.T) {
 }
 
 func TestShadowedNestedValue(t *testing.T) {
-
 	config := `name: steve
 clothing:
   jacket: leather
@@ -1898,7 +1886,6 @@ func doTestCaseInsensitive(t *testing.T, typ, config string) {
 	assert.Equal(t, 3, cast.ToInt(Get("ef.ijk")))
 	assert.Equal(t, 4, cast.ToInt(Get("ef.lm.no")))
 	assert.Equal(t, 5, cast.ToInt(Get("ef.lm.p.q")))
-
 }
 
 func newViperWithConfigFile(t *testing.T) (*Viper, string, func()) {
@@ -2003,7 +1990,6 @@ func TestWatchFile(t *testing.T) {
 		require.Nil(t, err)
 		assert.Equal(t, "baz", v.Get("foo"))
 	})
-
 }
 
 func TestUnmarshal_DotSeparatorBackwardCompatibility(t *testing.T) {