dev: replace sliceutil package with exp/slices (#3830)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
parent
aad2e22526
commit
c7b50f67c9
2
go.mod
2
go.mod
@ -113,6 +113,7 @@ require (
|
|||||||
github.com/ykadowak/zerologlint v0.1.1
|
github.com/ykadowak/zerologlint v0.1.1
|
||||||
gitlab.com/bosi/decorder v0.2.3
|
gitlab.com/bosi/decorder v0.2.3
|
||||||
go.tmz.dev/musttag v0.6.1
|
go.tmz.dev/musttag v0.6.1
|
||||||
|
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea
|
||||||
golang.org/x/tools v0.8.0
|
golang.org/x/tools v0.8.0
|
||||||
gopkg.in/yaml.v3 v3.0.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
honnef.co/go/tools v0.4.3
|
honnef.co/go/tools v0.4.3
|
||||||
@ -182,7 +183,6 @@ require (
|
|||||||
go.uber.org/atomic v1.7.0 // indirect
|
go.uber.org/atomic v1.7.0 // indirect
|
||||||
go.uber.org/multierr v1.6.0 // indirect
|
go.uber.org/multierr v1.6.0 // indirect
|
||||||
go.uber.org/zap v1.24.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/exp/typeparams v0.0.0-20230224173230-c95f2b4c22f2 // indirect
|
||||||
golang.org/x/mod v0.10.0 // indirect
|
golang.org/x/mod v0.10.0 // indirect
|
||||||
golang.org/x/sync v0.1.0 // indirect
|
golang.org/x/sync v0.1.0 // indirect
|
||||||
|
4
go.sum
generated
4
go.sum
generated
@ -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-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-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-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-20230510235704-dd950f8aeaea h1:vLCWI/yYrdEHyN2JzIzPO3aaQJHQdp89IZBA/+azVC4=
|
||||||
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
|
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-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-20230203172020-98cc5a0785f9/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
|
||||||
golang.org/x/exp/typeparams v0.0.0-20230224173230-c95f2b4c22f2 h1:J74nGeMgeFnYQJN59eFwh06jX/V8g0lB7LWpjSLxtgU=
|
golang.org/x/exp/typeparams v0.0.0-20230224173230-c95f2b4c22f2 h1:J74nGeMgeFnYQJN59eFwh06jX/V8g0lB7LWpjSLxtgU=
|
||||||
|
@ -9,11 +9,11 @@ import (
|
|||||||
|
|
||||||
"github.com/mitchellh/go-homedir"
|
"github.com/mitchellh/go-homedir"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
"github.com/golangci/golangci-lint/pkg/exitcodes"
|
"github.com/golangci/golangci-lint/pkg/exitcodes"
|
||||||
"github.com/golangci/golangci-lint/pkg/fsutils"
|
"github.com/golangci/golangci-lint/pkg/fsutils"
|
||||||
"github.com/golangci/golangci-lint/pkg/logutils"
|
"github.com/golangci/golangci-lint/pkg/logutils"
|
||||||
"github.com/golangci/golangci-lint/pkg/sliceutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type FileReader struct {
|
type FileReader struct {
|
||||||
@ -203,7 +203,7 @@ func (r *FileReader) setupConfigFileSearch() {
|
|||||||
// find home directory for global config
|
// find home directory for global config
|
||||||
if home, err := homedir.Dir(); err != nil {
|
if home, err := homedir.Dir(); err != nil {
|
||||||
r.log.Warnf("Can't get user's home directory: %s", err.Error())
|
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)
|
configSearchPaths = append(configSearchPaths, home)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
|
||||||
}
|
|
@ -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"))
|
|
||||||
}
|
|
@ -6,6 +6,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"golang.org/x/exp/slices"
|
||||||
|
|
||||||
"github.com/golangci/golangci-lint/pkg/lint/lintersdb"
|
"github.com/golangci/golangci-lint/pkg/lint/lintersdb"
|
||||||
"github.com/golangci/golangci-lint/test/testshared"
|
"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 {
|
func getEnabledByDefaultFastLintersExcept(except ...string) []string {
|
||||||
m := lintersdb.NewManager(nil, nil)
|
m := lintersdb.NewManager(nil, nil)
|
||||||
ebdl := m.GetAllEnabledByDefaultLinters()
|
ebdl := m.GetAllEnabledByDefaultLinters()
|
||||||
@ -153,7 +145,7 @@ func getEnabledByDefaultFastLintersExcept(except ...string) []string {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if !inSlice(except, lc.Name()) {
|
if !slices.Contains(except, lc.Name()) {
|
||||||
ret = append(ret, lc.Name())
|
ret = append(ret, lc.Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user