1 package s1029
2 3 import (
4 "honnef.co/go/tools/analysis/lint"
5 "honnef.co/go/tools/internal/passes/buildir"
6 "honnef.co/go/tools/internal/sharedcheck"
7 8 "golang.org/x/tools/go/analysis"
9 )
10 11 var SCAnalyzer = lint.InitializeAnalyzer(&lint.Analyzer{
12 Analyzer: &analysis.Analyzer{
13 Name: "S1029",
14 Run: sharedcheck.CheckRangeStringRunes,
15 Requires: []*analysis.Analyzer{buildir.Analyzer},
16 },
17 Doc: &lint.RawDocumentation{
18 Title: `Range over the string directly`,
19 Text: `Ranging over a string will yield byte offsets and runes. If the offset
20 isn't used, this is functionally equivalent to converting the string
21 to a slice of runes and ranging over that. Ranging directly over the
22 string will be more performant, however, as it avoids allocating a new
23 slice, the size of which depends on the length of the string.`,
24 Before: `for _, r := range []rune(s) {}`,
25 After: `for _, r := range s {}`,
26 Since: "2017.1",
27 MergeIf: lint.MergeIfAny,
28 },
29 })
30 31 var Analyzer = SCAnalyzer.Analyzer
32