Skip to content

Commit 431a945

Browse files
mmorel-35MrAlias
andauthored
chore: enable more rules from go-critic (#7647)
Signed-off-by: Matthieu MOREL <[email protected]> Co-authored-by: Tyler Yahn <[email protected]>
1 parent 67080e8 commit 431a945

File tree

11 files changed

+68
-59
lines changed

11 files changed

+68
-59
lines changed

.golangci.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,11 @@ linters:
5454
gocritic:
5555
disabled-checks:
5656
- appendAssign
57-
- appendCombine
58-
- assignOp
59-
- elseif
6057
- exitAfterDefer
6158
- exposedSyncMutex
6259
- hugeParam
6360
- rangeValCopy
64-
- typeUnparen
6561
- unnamedResult
66-
- unslice
6762
- whyNoLint
6863
enable-all: true
6964
godot:

detectors/gcp/detector.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,11 @@ func (r *resourceBuilder) addInt(key attribute.Key, detect func() (string, error
121121
// zoneAndRegion functions are expected to return zone, region, err.
122122
func (r *resourceBuilder) addZoneAndRegion(detect func() (string, string, error)) {
123123
if zone, region, err := detect(); err == nil {
124-
r.attrs = append(r.attrs, semconv.CloudAvailabilityZone(zone))
125-
r.attrs = append(r.attrs, semconv.CloudRegion(region))
124+
r.attrs = append(
125+
r.attrs,
126+
semconv.CloudAvailabilityZone(zone),
127+
semconv.CloudRegion(region),
128+
)
126129
} else {
127130
r.errs = append(r.errs, err)
128131
}

instrumentation/github.com/aws/aws-lambda-go/otellambda/xrayconfig/collector_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ func (s *SpansStorage) AddSpans(request *collectortracepb.ExportTraceServiceRequ
4444
}
4545
}
4646
s.spanCount += len(rs.ScopeSpans[0].Spans)
47-
} else {
48-
if len(rs.ScopeSpans) > 0 {
49-
newSpans := rs.ScopeSpans[0].GetSpans()
50-
existingRs.ScopeSpans[0].Spans = append(existingRs.ScopeSpans[0].Spans, newSpans...)
51-
s.spanCount += len(newSpans)
52-
}
47+
} else if len(rs.ScopeSpans) > 0 {
48+
newSpans := rs.ScopeSpans[0].GetSpans()
49+
existingRs.ScopeSpans[0].Spans = append(existingRs.ScopeSpans[0].Spans, newSpans...)
50+
s.spanCount += len(newSpans)
5351
}
5452
}
5553
}
@@ -76,13 +74,13 @@ func resourceString(res *resourcepb.Resource) string {
7674
sAttrs := sortedAttributes(res.GetAttributes())
7775
rstr := ""
7876
for _, attr := range sAttrs {
79-
rstr = rstr + attr.String()
77+
rstr += attr.String()
8078
}
8179
return rstr
8280
}
8381

8482
func sortedAttributes(attrs []*commonpb.KeyValue) []*commonpb.KeyValue {
85-
sort.Slice(attrs[:], func(i, j int) bool {
83+
sort.Slice(attrs, func(i, j int) bool {
8684
return attrs[i].Key < attrs[j].Key
8785
})
8886
return attrs

instrumentation/github.com/aws/aws-lambda-go/otellambda/xrayconfig/mock_collector_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func runMockCollectorWithConfig(t *testing.T, mockConfig *mockConfig) *mockColle
136136
collectortracepb.RegisterTraceServiceServer(srv, mc.traceSvc)
137137
mc.ln = newListener(ln)
138138
go func() {
139-
_ = srv.Serve((net.Listener)(mc.ln))
139+
_ = srv.Serve(net.Listener(mc.ln))
140140
}()
141141

142142
mc.endpoint = ln.Addr().String()

instrumentation/github.com/emicklei/go-restful/otelrestful/restfultest_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func TestChildSpanNames(t *testing.T) {
8282
container.Add(ws)
8383

8484
ws.Route(ws.GET("/book/{title}").To(func(_ *restful.Request, resp *restful.Response) {
85-
_, _ = resp.Write(([]byte)("ok"))
85+
_, _ = resp.Write([]byte("ok"))
8686
}))
8787

8888
r := httptest.NewRequest(http.MethodGet, "/user/123", http.NoBody)

instrumentation/github.com/gorilla/mux/otelmux/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func Example() {
3939
id := vars["id"]
4040
name := getUser(r.Context(), id)
4141
reply := fmt.Sprintf("user %s (id %s)\n", name, id)
42-
_, _ = w.Write(([]byte)(reply))
42+
_, _ = w.Write([]byte(reply))
4343
}))
4444
http.Handle("/", r)
4545
_ = http.ListenAndServe(":8080", nil) //nolint:gosec // Ignoring G114: Use of net/http serve function that has no support for setting timeouts.

instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/internal/semconv/event_monitor.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,19 @@ func commandStartedTraceAttrs(evt *event.CommandStartedEvent, setters ...Attribu
135135

136136
attrs := []attribute.KeyValue{semconv.DBSystemNameMongoDB}
137137

138-
attrs = append(attrs, semconv.DBOperationName(evt.CommandName))
139-
attrs = append(attrs, semconv.DBNamespace(evt.DatabaseName))
140-
attrs = append(attrs, semconv.NetworkTransportTCP)
138+
attrs = append(
139+
attrs,
140+
semconv.DBOperationName(evt.CommandName),
141+
semconv.DBNamespace(evt.DatabaseName),
142+
semconv.NetworkTransportTCP,
143+
)
141144

142145
hostname, port := peerInfo(evt)
143-
attrs = append(attrs, semconv.NetworkPeerPort(port))
144-
attrs = append(attrs, semconv.NetworkPeerAddress(net.JoinHostPort(hostname, strconv.Itoa(port))))
146+
attrs = append(
147+
attrs,
148+
semconv.NetworkPeerPort(port),
149+
semconv.NetworkPeerAddress(net.JoinHostPort(hostname, strconv.Itoa(port))),
150+
)
145151

146152
if !opts.commandAttributeDisabled {
147153
attrs = append(attrs, semconv.DBQueryText(sanitizeCommand(evt.Command)))
@@ -164,13 +170,19 @@ func commandStartedTraceAttrsV1210(evt *event.CommandStartedEvent, setters ...At
164170

165171
attrs := []attribute.KeyValue{semconv1210.DBSystemMongoDB}
166172

167-
attrs = append(attrs, semconv1210.DBOperation(evt.CommandName))
168-
attrs = append(attrs, semconv1210.DBName(evt.DatabaseName))
169-
attrs = append(attrs, semconv1210.NetTransportTCP)
173+
attrs = append(
174+
attrs,
175+
semconv1210.DBOperation(evt.CommandName),
176+
semconv1210.DBName(evt.DatabaseName),
177+
semconv1210.NetTransportTCP,
178+
)
170179

171180
hostname, port := peerInfo(evt)
172-
attrs = append(attrs, semconv1210.NetPeerPort(port))
173-
attrs = append(attrs, semconv1210.NetPeerName(hostname))
181+
attrs = append(
182+
attrs,
183+
semconv1210.NetPeerPort(port),
184+
semconv1210.NetPeerName(hostname),
185+
)
174186

175187
if !opts.commandAttributeDisabled {
176188
attrs = append(attrs, semconv1210.DBStatement(sanitizeCommand(evt.Command)))

instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/test/mongo_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ func TestDBCrudOperation(t *testing.T) {
8585

8686
title := tc.title
8787
if tc.excludeCommand {
88-
title = title + "/excludeCommand"
88+
title += "/excludeCommand"
8989
} else {
90-
title = title + "/includeCommand"
90+
title += "/includeCommand"
9191
}
9292

9393
mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))

instrumentation/go.mongodb.org/mongo-driver/v2/mongo/otelmongo/mongo_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ func TestDBCrudOperation(t *testing.T) {
8585

8686
title := tc.title
8787
if tc.excludeCommand {
88-
title = title + "/excludeCommand"
88+
title += "/excludeCommand"
8989
} else {
90-
title = title + "/includeCommand"
90+
title += "/includeCommand"
9191
}
9292

9393
t.Run(title, func(t *testing.T) {

propagators/aws/xray/propagator_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,8 @@ func TestInject(t *testing.T) {
271271
if headerVal != tc.wantHeaderVal {
272272
t.Errorf("expected header value %q, got %q", tc.wantHeaderVal, headerVal)
273273
}
274-
} else {
275-
if headerVal != "" {
276-
t.Errorf("expected no header to be set, but got %q", headerVal)
277-
}
274+
} else if headerVal != "" {
275+
t.Errorf("expected no header to be set, but got %q", headerVal)
278276
}
279277
})
280278
}

0 commit comments

Comments
 (0)