diff --git a/utils/collection/modify.go b/utils/collection/modify.go index fba08dbe01..d1da6053c9 100644 --- a/utils/collection/modify.go +++ b/utils/collection/modify.go @@ -4,6 +4,8 @@ */ package collection +import "slices" + // Remove looks for elements in a slice. If they're found, it will // remove them. func Remove(slice []string, val ...string) []string { @@ -16,6 +18,9 @@ func GenericRemove(equal func(string, string) bool, slice []string, val ...strin if len(val) == 0 { return slice } + if len(val) == 1 { + return slices.DeleteFunc(slice, func(v string) bool { return equal(v, val[0]) }) + } list := make([]string, 0, len(slice)) found := make([]bool, len(val)) diff --git a/utils/collection/search.go b/utils/collection/search.go index 678d8e0d62..33b2ce8ca1 100644 --- a/utils/collection/search.go +++ b/utils/collection/search.go @@ -5,6 +5,7 @@ package collection import ( + "slices" "strings" mapset "github.com/deckarep/golang-set/v2" @@ -25,6 +26,10 @@ func FindInSlice(strict bool, slice []string, val ...string) (int, bool) { if len(val) == 0 || len(slice) == 0 { return -1, false } + if strict && len(val) == 1 { + idx := slices.Index(slice, val[0]) + return idx, idx >= 0 + } inSlice := make(map[string]int, len(slice)) for i := range slice { diff --git a/utils/filesystem/limits_test.go b/utils/filesystem/limits_test.go index 649d5dbe23..48369a1342 100644 --- a/utils/filesystem/limits_test.go +++ b/utils/filesystem/limits_test.go @@ -8,8 +8,8 @@ import ( ) func TestNewLimits(t *testing.T) { - require.NoError(t, NoLimits().Validate()) - require.NoError(t, DefaultLimits().Validate()) + require.NoError(t, NoLimits().Validate()) //nolint:typecheck + require.NoError(t, DefaultLimits().Validate()) //nolint:typecheck assert.True(t, DefaultLimits().Apply()) assert.False(t, NoLimits().Apply()) } diff --git a/utils/git/config_test.go b/utils/git/config_test.go index 48b1de7355..7dd5cab1e9 100644 --- a/utils/git/config_test.go +++ b/utils/git/config_test.go @@ -7,5 +7,5 @@ import ( ) func TestNewConfig(t *testing.T) { - require.NoError(t, DefaultLimits().Validate()) + require.NoError(t, DefaultLimits().Validate()) //nolint:typecheck } diff --git a/utils/git/limits_test.go b/utils/git/limits_test.go index 763f3663df..8346a74ed9 100644 --- a/utils/git/limits_test.go +++ b/utils/git/limits_test.go @@ -8,8 +8,8 @@ import ( ) func TestNewLimits(t *testing.T) { - require.NoError(t, NoLimits().Validate()) - require.NoError(t, DefaultLimits().Validate()) + require.NoError(t, NoLimits().Validate()) //nolint:typecheck + require.NoError(t, DefaultLimits().Validate()) //nolint:typecheck assert.True(t, DefaultLimits().Apply()) assert.False(t, NoLimits().Apply()) }