Debian Codegraph @

gopls/internal/analysis/maprange/doc.go

raw symbols SCIP
1 // Copyright 2025 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Package maprange defines an Analyzer that checks for redundant use
6 // of the functions maps.Keys and maps.Values in "for" statements with
7 // "range" clauses.
8 //
9 // # Analyzer maprange
10 //
11 // maprange: checks for unnecessary calls to maps.Keys and maps.Values in range statements
12 //
13 // Consider a loop written like this:
14 //
15 // for val := range maps.Values(m) {
16 // fmt.Println(val)
17 // }
18 //
19 // This should instead be written without the call to maps.Values:
20 //
21 // for _, val := range m {
22 // fmt.Println(val)
23 // }
24 //
25 // golang.org/x/exp/maps returns slices for Keys/Values instead of iterators,
26 // but unnecessary calls should similarly be removed:
27 //
28 // for _, key := range maps.Keys(m) {
29 // fmt.Println(key)
30 // }
31 //
32 // should be rewritten as:
33 //
34 // for key := range m {
35 // fmt.Println(key)
36 // }
37 package maprange