From a791da161000ab2e03cbcf9af482ac092c3d024c Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Thu, 11 May 2023 12:43:56 +0300 Subject: [PATCH] dev: replace sliceutil package with exp/slices --- go.mod | 2 +- pkg/config/reader.go | 4 ++-- pkg/sliceutil/sliceutil.go | 17 ----------------- pkg/sliceutil/sliceutil_test.go | 17 ----------------- test/enabled_linters_test.go | 14 +++----------- 5 files changed, 6 insertions(+), 48 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 a504af2426b9..5e8ee8c57a3e 100644 --- a/go.mod +++ b/go.mod @@ -182,7 +182,7 @@ 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 v0.0.0-20220722155223-a9213eeb770e 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/pkg/config/reader.go b/pkg/config/reader.go index 2199fdd2de33..1fb995e853a6 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 cb89e34e0c3a..000000000000 --- 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 647125bf1814..000000000000 --- 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 7a2aa702ccd5..622b0a2cd05f 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()) } }