Documentation
¶
Overview ¶
Package maprange defines an Analyzer that checks for redundant use of the functions maps.Keys and maps.Values in "for" statements with "range" clauses.
Analyzer maprange ¶
maprange: checks for unnecessary calls to maps.Keys and maps.Values in range statements
Consider a loop written like this:
for val := range maps.Values(m) { fmt.Println(val) }
This should instead be written without the call to maps.Values:
for _, val := range m { fmt.Println(val) }
golang.org/x/exp/maps returns slices for Keys/Values instead of iterators, but unnecessary calls should similarly be removed:
for _, key := range maps.Keys(m) { fmt.Println(key) }
should be rewritten as:
for key := range m { fmt.Println(key) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Analyzer = &analysis.Analyzer{ Name: "maprange", Doc: analysisinternal.MustExtractDoc(doc, "maprange"), URL: "https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/maprange", Requires: []*analysis.Analyzer{typeindexanalyzer.Analyzer}, Run: run, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
maprange
The maprange command applies the golang.org/x/tools/gopls/internal/analysis/maprange analysis to the specified packages of Go source code.
|
The maprange command applies the golang.org/x/tools/gopls/internal/analysis/maprange analysis to the specified packages of Go source code. |
Click to show internal directories.
Click to hide internal directories.