Debian Codegraph @

go/analysis/passes/modernize/testdata/src/splitseq/splitseq.go

raw
1 //go:build go1.24
2
3 package splitseq
4
5 import (
6 "bytes"
7 "strings"
8 )
9
10 func _() {
11 for _, line := range strings.Split("", "") { // want "Ranging over SplitSeq is more efficient"
12 println(line)
13 }
14 for i, line := range strings.Split("", "") { // nope: uses index var
15 println(i, line)
16 }
17 for i, _ := range strings.Split("", "") { // nope: uses index var
18 println(i)
19 }
20 for i := range strings.Split("", "") { // nope: uses index var
21 println(i)
22 }
23 for _ = range strings.Split("", "") { // want "Ranging over SplitSeq is more efficient"
24 }
25 for range strings.Split("", "") { // want "Ranging over SplitSeq is more efficient"
26 }
27 for range bytes.Split(nil, nil) { // want "Ranging over SplitSeq is more efficient"
28 }
29 {
30 lines := strings.Split("", "") // want "Ranging over SplitSeq is more efficient"
31 for _, line := range lines {
32 println(line)
33 }
34 }
35 {
36 lines := strings.Split("", "") // nope: lines is used not just by range
37 for _, line := range lines {
38 println(line)
39 }
40 println(lines)
41 }
42 }