Add staticcheck tool
This commit is contained in:
42
vendor/honnef.co/go/tools/staticcheck/sa6003/sa6003.go
vendored
Normal file
42
vendor/honnef.co/go/tools/staticcheck/sa6003/sa6003.go
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
package sa6003
|
||||
|
||||
import (
|
||||
"honnef.co/go/tools/analysis/lint"
|
||||
"honnef.co/go/tools/internal/passes/buildir"
|
||||
"honnef.co/go/tools/internal/sharedcheck"
|
||||
|
||||
"golang.org/x/tools/go/analysis"
|
||||
)
|
||||
|
||||
var SCAnalyzer = lint.InitializeAnalyzer(&lint.Analyzer{
|
||||
Analyzer: &analysis.Analyzer{
|
||||
Name: "SA6003",
|
||||
Run: sharedcheck.CheckRangeStringRunes,
|
||||
Requires: []*analysis.Analyzer{buildir.Analyzer},
|
||||
},
|
||||
Doc: &lint.RawDocumentation{
|
||||
Title: `Converting a string to a slice of runes before ranging over it`,
|
||||
Text: `You may want to loop over the runes in a string. Instead of converting
|
||||
the string to a slice of runes and looping over that, you can loop
|
||||
over the string itself. That is,
|
||||
|
||||
for _, r := range s {}
|
||||
|
||||
and
|
||||
|
||||
for _, r := range []rune(s) {}
|
||||
|
||||
will yield the same values. The first version, however, will be faster
|
||||
and avoid unnecessary memory allocations.
|
||||
|
||||
Do note that if you are interested in the indices, ranging over a
|
||||
string and over a slice of runes will yield different indices. The
|
||||
first one yields byte offsets, while the second one yields indices in
|
||||
the slice of runes.`,
|
||||
Since: "2017.1",
|
||||
Severity: lint.SeverityWarning,
|
||||
MergeIf: lint.MergeIfAny,
|
||||
},
|
||||
})
|
||||
|
||||
var Analyzer = SCAnalyzer.Analyzer
|
||||
Reference in New Issue
Block a user