From c7b50f67c98205e89c475d71aef1ccf3b95ce98b Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Fri, 12 May 2023 04:27:23 +0300 Subject: [PATCH] dev: replace sliceutil package with exp/slices (#3830) Co-authored-by: Fernandez Ludovic --- go.mod | 2 +- go.sum | 4 ++-- pkg/config/reader.go | 4 ++-- pkg/sliceutil/sliceutil.go | 17 ----------------- pkg/sliceutil/sliceutil_test.go | 17 ----------------- test/enabled_linters_test.go | 14 +++----------- 6 files changed, 8 insertions(+), 50 deletions(-) delete mode 100644 pkg/sliceutil/sliceutil.go delete mode 100644 pkg/sliceutil/sliceutil_test.go diff --git a/go.mod b/go.mod index a504af24..1a8f26b6 100644 --- a/go.mod +++ b/go.mod @@ -113,6 +113,7 @@ require ( github.com/ykadowak/zerologlint v0.1.1 gitlab.com/bosi/decorder v0.2.3 go.tmz.dev/musttag v0.6.1 + golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea golang.org/x/tools v0.8.0 gopkg.in/yaml.v3 v3.0.1 honnef.co/go/tools v0.4.3 @@ -182,7 +183,6 @@ require ( go.uber.org/atomic v1.7.0 // indirect go.uber.org/multierr v1.6.0 // indirect go.uber.org/zap v1.24.0 // indirect - golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect golang.org/x/exp/typeparams v0.0.0-20230224173230-c95f2b4c22f2 // indirect golang.org/x/mod v0.10.0 // indirect golang.org/x/sync v0.1.0 // indirect diff --git a/go.sum b/go.sum index b8ea41ca..f3c5026e 100644 --- a/go.sum +++ b/go.sum @@ -610,8 +610,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA= -golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA= +golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea h1:vLCWI/yYrdEHyN2JzIzPO3aaQJHQdp89IZBA/+azVC4= +golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= golang.org/x/exp/typeparams v0.0.0-20220428152302-39d4317da171/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/exp/typeparams v0.0.0-20230203172020-98cc5a0785f9/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/exp/typeparams v0.0.0-20230224173230-c95f2b4c22f2 h1:J74nGeMgeFnYQJN59eFwh06jX/V8g0lB7LWpjSLxtgU= diff --git a/pkg/config/reader.go b/pkg/config/reader.go index 2199fdd2..1fb995e8 100644 --- a/pkg/config/reader.go +++ b/pkg/config/reader.go @@ -9,11 +9,11 @@ import ( "github.com/mitchellh/go-homedir" "github.com/spf13/viper" + "golang.org/x/exp/slices" "github.com/golangci/golangci-lint/pkg/exitcodes" "github.com/golangci/golangci-lint/pkg/fsutils" "github.com/golangci/golangci-lint/pkg/logutils" - "github.com/golangci/golangci-lint/pkg/sliceutil" ) type FileReader struct { @@ -203,7 +203,7 @@ func (r *FileReader) setupConfigFileSearch() { // find home directory for global config if home, err := homedir.Dir(); err != nil { r.log.Warnf("Can't get user's home directory: %s", err.Error()) - } else if !sliceutil.Contains(configSearchPaths, home) { + } else if !slices.Contains(configSearchPaths, home) { configSearchPaths = append(configSearchPaths, home) } diff --git a/pkg/sliceutil/sliceutil.go b/pkg/sliceutil/sliceutil.go deleted file mode 100644 index cb89e34e..00000000 --- a/pkg/sliceutil/sliceutil.go +++ /dev/null @@ -1,17 +0,0 @@ -package sliceutil - -// IndexOf get the index of the given value in the given string slice, -// or -1 if not found. -func IndexOf(slice []string, value string) int { - for i, v := range slice { - if v == value { - return i - } - } - return -1 -} - -// Contains check if a string slice contains a value. -func Contains(slice []string, value string) bool { - return IndexOf(slice, value) != -1 -} diff --git a/pkg/sliceutil/sliceutil_test.go b/pkg/sliceutil/sliceutil_test.go deleted file mode 100644 index 647125bf..00000000 --- a/pkg/sliceutil/sliceutil_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package sliceutil - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestContains(t *testing.T) { - assert.True(t, Contains([]string{"val1", "val2", "val3"}, "val2")) - assert.False(t, Contains([]string{"val1", "val2", "val3"}, "val4")) -} - -func TestIndexOf(t *testing.T) { - assert.Equal(t, 1, IndexOf([]string{"val1", "val2", "val3"}, "val2")) - assert.Equal(t, -1, IndexOf([]string{"val1", "val2", "val3"}, "val4")) -} diff --git a/test/enabled_linters_test.go b/test/enabled_linters_test.go index 7a2aa702..622b0a2c 100644 --- a/test/enabled_linters_test.go +++ b/test/enabled_linters_test.go @@ -6,6 +6,8 @@ import ( "strings" "testing" + "golang.org/x/exp/slices" + "github.com/golangci/golangci-lint/pkg/lint/lintersdb" "github.com/golangci/golangci-lint/test/testshared" ) @@ -134,16 +136,6 @@ func TestEnabledLinters(t *testing.T) { } } -func inSlice(s []string, v string) bool { - for _, sv := range s { - if sv == v { - return true - } - } - - return false -} - func getEnabledByDefaultFastLintersExcept(except ...string) []string { m := lintersdb.NewManager(nil, nil) ebdl := m.GetAllEnabledByDefaultLinters() @@ -153,7 +145,7 @@ func getEnabledByDefaultFastLintersExcept(except ...string) []string { continue } - if !inSlice(except, lc.Name()) { + if !slices.Contains(except, lc.Name()) { ret = append(ret, lc.Name()) } }