maprange

package
v0.19.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2025 License: BSD-3-Clause Imports: 12 Imported by: 0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL