Skip to content

Commit 0da0d76

Browse files
mxschmittclaude
andcommitted
refactor: use slices.Contains in more places
- workertypes.IsValid(): replace manual loop with slices.Contains - worker-java transformOutput(): simplify forbidden line filtering Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f237b83 commit 0da0d76

2 files changed

Lines changed: 5 additions & 14 deletions

File tree

internal/workertypes/types.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package workertypes
22

3+
import "slices"
4+
35
type File struct {
46
PublicURL string `json:"publicURL"`
57
FileName string `json:"fileName"`
@@ -38,10 +40,5 @@ var SUPPORTED_LANGUAGES = []WorkerLanguage{
3840
}
3941

4042
func (givenLanguage WorkerLanguage) IsValid() bool {
41-
for _, language := range SUPPORTED_LANGUAGES {
42-
if string(givenLanguage) == string(language) {
43-
return true
44-
}
45-
}
46-
return false
43+
return slices.Contains(SUPPORTED_LANGUAGES, givenLanguage)
4744
}

worker-java/main.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os/exec"
88
"path/filepath"
99
"regexp"
10+
"slices"
1011
"strings"
1112

1213
"github.com/mxschmitt/try-playwright/internal/worker"
@@ -49,14 +50,7 @@ func transformOutput(input string) string {
4950
lines := strings.Split(input, NEW_LINE_SEPARATOR)
5051
out := []string{}
5152
for _, line := range lines {
52-
lineIsOk := true
53-
for _, forbidenLine := range forbiddenLines {
54-
if forbidenLine == line {
55-
lineIsOk = false
56-
break
57-
}
58-
}
59-
if lineIsOk {
53+
if !slices.Contains(forbiddenLines, line) {
6054
out = append(out, line)
6155
}
6256
}

0 commit comments

Comments
 (0)