Skip to content

Commit b5dad65

Browse files
committed
refactor: make use of strings.Cut
1 parent d236c63 commit b5dad65

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

language/js/configure.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,19 +210,19 @@ func (ts *typeScriptLang) readDirectives(c *config.Config, rel string, f *rule.F
210210
group := DefaultLibraryName
211211
groupGlob := value
212212

213-
if i := strings.Index(value, " "); i != -1 {
214-
group = value[:i]
215-
groupGlob = strings.TrimSpace(value[i+1:])
213+
if before, after, found := strings.Cut(value, " "); found {
214+
group = before
215+
groupGlob = strings.TrimSpace(after)
216216
}
217217

218218
config.addTargetGlob(group, groupGlob, false)
219219
case Directive_TestFiles:
220220
group := DefaultTestsName
221221
groupGlob := value
222222

223-
if i := strings.Index(value, " "); i != -1 {
224-
group = value[:i]
225-
groupGlob = strings.TrimSpace(value[i+1:])
223+
if before, after, found := strings.Cut(value, " "); found {
224+
group = before
225+
groupGlob = strings.TrimSpace(after)
226226
}
227227

228228
config.addTargetGlob(group, groupGlob, true)

runner/bin/gazelle/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func extractArg(flag string, defaultValue string, args []string) (string, []stri
122122
return value, args
123123
}
124124

125-
value := strings.SplitN(args[i], "=", 2)[1]
125+
_, value, _ := strings.Cut(args[i], "=")
126126
args = append(args[:i], args[i+1:]...)
127127
return value, args
128128
}

runner/pkg/git/gitignore_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ func TestGitIgnore(t *testing.T) {
1212
shouldMatch := func(what string, matcher isGitIgnored, matches ...string) {
1313
for _, m := range matches {
1414
// Use trailing slash in test data to indicate directory
15-
isDir := strings.HasSuffix(m, "/")
16-
m = strings.TrimSuffix(m, "/")
15+
m, isDir := strings.CutSuffix(m, "/")
1716

1817
if !(matcher != nil && matcher(m, isDir)) {
1918
t.Error(fmt.Sprintf("%s should match '%s'", what, m))
@@ -23,8 +22,7 @@ func TestGitIgnore(t *testing.T) {
2322
shouldNotMatch := func(what string, matcher isGitIgnored, matches ...string) {
2423
for _, m := range matches {
2524
// Use trailing slash in test data to indicate directory
26-
isDir := strings.HasSuffix(m, "/")
27-
m = strings.TrimSuffix(m, "/")
25+
m, isDir := strings.CutSuffix(m, "/")
2826

2927
if matcher != nil && matcher(m, isDir) {
3028
t.Error(fmt.Sprintf("%s should NOT match '%s'", what, m))

0 commit comments

Comments
 (0)