Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions internal/sliceutils/sliceutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ package sliceutils

import "golang.org/x/text/unicode/norm"

func RemoveFromStrings(slice []string, n int) []string {
return append(slice[:n], slice[n+1:]...)
func RemoveFromStrings(slice []string, indexes ...int) []string {
var out []string
for i, s := range slice {
if !intsContain(indexes, i) {
out = append(out, s)
}
}
return out[:len(out)]
}

func GetInt(slice []int, index int) (int, bool) {
Expand All @@ -26,4 +32,13 @@ func IntRangeUncapped(in []int, start, end int) []int {
end = len(in)
}
return in[start:end]
}
}

func intsContain(ns []int, v int) bool {
for _, n := range ns {
if n == v {
return true
}
}
return false
}
53 changes: 43 additions & 10 deletions internal/sliceutils/sliceutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,59 @@ import (
func TestRemoveFromStrings(t *testing.T) {
type args struct {
slice []string
n int
ns []int
}

simpleSlice := []string{"0", "1", "2", "3"}
integers := func(ns ...int) []int { return ns }

tests := []struct {
name string
args args
want []string
}{
{
"Removes Index",
args{
[]string{"1", "2", "3"},
1,
},
[]string{"1", "3"},
"first index",
args{simpleSlice, integers(0)},
[]string{"1", "2", "3"},
},
{
"last index",
args{simpleSlice, integers(len(simpleSlice) - 1)},
[]string{"0", "1", "2"},
},
{
"inner index",
args{simpleSlice, integers(1)},
[]string{"0", "2", "3"},
},
{
"multiple indexes",
args{simpleSlice, integers(1, len(simpleSlice)-1)},
[]string{"0", "2"},
},
{
"index too low",
args{simpleSlice, integers(-1)},
simpleSlice,
},
{
"index too high",
args{simpleSlice, integers(42)},
simpleSlice,
},
{
"nil indexes",
args{simpleSlice, nil},
simpleSlice,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := RemoveFromStrings(tt.args.slice, tt.args.n); !reflect.DeepEqual(got, tt.want) {
t.Errorf("RemoveFromStrings() = %v, want %v", got, tt.want)
got := RemoveFromStrings(tt.args.slice, tt.args.ns...)
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("got %v, want %v", got, tt.want)
}
})
}
Expand Down Expand Up @@ -148,4 +181,4 @@ func TestRange(t *testing.T) {
}
})
}
}
}
4 changes: 3 additions & 1 deletion pkg/projectfile/projectfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1314,11 +1314,13 @@ func CleanProjectMapping(cfg ConfigGetter) {
seen := map[string]bool{}

for namespace, paths := range projects {
var removals []int
for i, path := range paths {
if !fileutils.DirExists(path) {
projects[namespace] = sliceutils.RemoveFromStrings(projects[namespace], i)
removals = append(removals, i)
}
}
projects[namespace] = sliceutils.RemoveFromStrings(projects[namespace], removals...)
if ok, _ := seen[strings.ToLower(namespace)]; ok || len(projects[namespace]) == 0 {
delete(projects, namespace)
continue
Expand Down