github.com/amarpal/go-tools@v0.0.0-20240422043104-40142f59f616/simple/s1029/s1029.go (about)

     1  package s1029
     2  
     3  import (
     4  	"github.com/amarpal/go-tools/analysis/lint"
     5  	"github.com/amarpal/go-tools/internal/passes/buildir"
     6  	"github.com/amarpal/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.Documentation{
    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