Skip to content

Commit 67552c5

Browse files
blgmonsi
authored andcommitted
chore: apply fixes from Go modernize command
The modernize command replaces old constructs with simpler, updated ones. Command is: go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...
1 parent 79b8a75 commit 67552c5

10 files changed

Lines changed: 17 additions & 24 deletions

File tree

format/format.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ func formatSlice(v reflect.Value, indentation uint) string {
422422
l := v.Len()
423423
result := make([]string, l)
424424
longest := 0
425-
for i := 0; i < l; i++ {
425+
for i := range l {
426426
result[i] = formatValue(v.Index(i), indentation+1)
427427
if len(result[i]) > longest {
428428
longest = len(result[i])
@@ -462,7 +462,7 @@ func formatStruct(v reflect.Value, indentation uint) string {
462462
l := v.NumField()
463463
result := []string{}
464464
longest := 0
465-
for i := 0; i < l; i++ {
465+
for i := range l {
466466
structField := t.Field(i)
467467
fieldEntry := v.Field(i)
468468
representation := fmt.Sprintf("%s: %s", structField.Name, formatValue(fieldEntry, indentation+1))

gbytes/io_wrappers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (f FakeReader) Read(p []byte) (int, error) {
3232
return 0, f.err
3333
}
3434

35-
for i := 0; i < len(p); i++ {
35+
for i := range p {
3636
p[i] = 'a'
3737
}
3838

ghttp/handlers.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/base64"
77
"encoding/json"
88
"fmt"
9+
"maps"
910
"net/http"
1011
"net/url"
1112
"reflect"
@@ -219,9 +220,7 @@ func (g GHTTPWithGomega) VerifyProtoRepresenting(expected protoiface.MessageV1)
219220
}
220221

221222
func copyHeader(src http.Header, dst http.Header) {
222-
for key, value := range src {
223-
dst[key] = value
224-
}
223+
maps.Copy(dst, src)
225224
}
226225

227226
/*

ghttp/test_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
254254
}()
255255

256256
if s.Writer != nil {
257-
s.Writer.Write([]byte(fmt.Sprintf("GHTTP Received Request: %s - %s\n", req.Method, req.URL)))
257+
s.Writer.Write(fmt.Appendf(nil, "GHTTP Received Request: %s - %s\n", req.Method, req.URL))
258258
}
259259

260260
s.receivedRequests = append(s.receivedRequests, req)

gmeasure/experiment.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,7 @@ func (e *Experiment) Sample(callback func(idx int), samplingConfig SamplingConfi
456456
if samplingConfig.N > 0 {
457457
maxN = samplingConfig.N
458458
}
459-
numParallel := 1
460-
if samplingConfig.NumParallel > numParallel {
461-
numParallel = samplingConfig.NumParallel
462-
}
459+
numParallel := max(samplingConfig.NumParallel, 1)
463460
minSamplingInterval := samplingConfig.MinSamplingInterval
464461

465462
work := make(chan int)

gmeasure/experiment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ var _ = Describe("Experiment", func() {
180180

181181
ints := func(n int) []int {
182182
out := []int{}
183-
for i := 0; i < n; i++ {
183+
for i := range n {
184184
out = append(out, i)
185185
}
186186
return out

matchers/have_key_matcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (matcher *HaveKeyMatcher) Match(actual any) (success bool, err error) {
3939
}
4040

4141
keys := reflect.ValueOf(actual).MapKeys()
42-
for i := 0; i < len(keys); i++ {
42+
for i := range keys {
4343
success, err := keyMatcher.Match(keys[i].Interface())
4444
if err != nil {
4545
return false, fmt.Errorf("HaveKey's key matcher failed with:\n%s%s", format.Indent, err.Error())

matchers/have_key_with_value_matcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (matcher *HaveKeyWithValueMatcher) Match(actual any) (success bool, err err
5252
}
5353

5454
keys := reflect.ValueOf(actual).MapKeys()
55-
for i := 0; i < len(keys); i++ {
55+
for i := range keys {
5656
success, err := keyMatcher.Match(keys[i].Interface())
5757
if err != nil {
5858
return false, fmt.Errorf("HaveKeyWithValue's key matcher failed with:\n%s%s", format.Indent, err.Error())

matchers/support/goraph/bipartitegraph/bipartitegraph_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ var _ = Describe("Bipartitegraph", func() {
105105
)
106106

107107
BeforeEach(func() {
108-
for i := 0; i < len(half); i++ {
108+
for i := range half {
109109
half[i] = i
110110
}
111111
discrete, _ = NewBipartiteGraph(half, half, discreteNeighbours)
@@ -152,7 +152,7 @@ var _ = Describe("Bipartitegraph", func() {
152152
)
153153

154154
BeforeEach(func() {
155-
for i := 0; i < len(half); i++ {
155+
for i := range half {
156156
half[i] = i
157157
}
158158
graph1, _ = NewBipartiteGraph(half, half, neighbours1)

matchers/support/goraph/edge/edge.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package edge
22

3-
import . "github.com/onsi/gomega/matchers/support/goraph/node"
3+
import (
4+
. "github.com/onsi/gomega/matchers/support/goraph/node"
5+
"slices"
6+
)
47

58
type Edge struct {
69
Node1 int
@@ -20,13 +23,7 @@ func (ec EdgeSet) Free(node Node) bool {
2023
}
2124

2225
func (ec EdgeSet) Contains(edge Edge) bool {
23-
for _, e := range ec {
24-
if e == edge {
25-
return true
26-
}
27-
}
28-
29-
return false
26+
return slices.Contains(ec, edge)
3027
}
3128

3229
func (ec EdgeSet) FindByNodes(node1, node2 Node) (Edge, bool) {

0 commit comments

Comments
 (0)