Skip to content

Commit 22248d4

Browse files
mmorel-35pellaredMrAlias
authored
chore: enable modernize linter (#8583)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> Co-authored-by: Robert Pająk <pellared@hotmail.com> Co-authored-by: Tyler Yahn <codingalias@gmail.com>
1 parent 324662a commit 22248d4

File tree

25 files changed

+65
-96
lines changed

25 files changed

+65
-96
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ linters:
1818
- govet
1919
- ineffassign
2020
- intrange
21+
- modernize
2122
- misspell
2223
- nolintlint
2324
- perfsprint

bridges/otelzap/core_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,12 @@ func TestCoreWriteContextConcurrentSafe(t *testing.T) {
187187
ctx = context.WithValue(ctx, testEntry, true)
188188

189189
var wg sync.WaitGroup
190-
wg.Add(1)
191-
go func() {
192-
defer wg.Done()
190+
wg.Go(func() {
193191
logger.Debug(testMessage, zap.Any("ctx", ctx))
194-
}()
195-
wg.Add(1)
196-
go func() {
197-
defer wg.Done()
192+
})
193+
wg.Go(func() {
198194
logger.Debug(testMessage, zap.Any("ctx", ctx))
199-
}()
195+
})
200196
wg.Wait()
201197

202198
want := logtest.Recording{

detectors/aws/ecs/ecs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ func (ecsDetectorUtils) getContainerName() (string, error) {
260260
}
261261

262262
func getCgroupContainerID(fileData []byte) string {
263-
splitData := strings.Split(strings.TrimSpace(string(fileData)), "\n")
264-
for _, str := range splitData {
263+
splitData := strings.SplitSeq(strings.TrimSpace(string(fileData)), "\n")
264+
for str := range splitData {
265265
if ecsCgroupPathPattern.MatchString(str) {
266266
return str[len(str)-containerIDLength:]
267267
}

detectors/aws/eks/detector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ func (eksDetectorUtils) getContainerID() (string, error) {
183183
}
184184

185185
// Retrieve containerID from file
186-
splitData := strings.Split(strings.TrimSpace(string(fileData)), "\n")
187-
for _, str := range splitData {
186+
splitData := strings.SplitSeq(strings.TrimSpace(string(fileData)), "\n")
187+
for str := range splitData {
188188
if containerIDRegex.MatchString(str) {
189189
return str[len(str)-containerIDLength:], nil
190190
}

exporters/autoexport/metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (pr producerRegistry) create(ctx context.Context) ([]metric.Producer, error
295295

296296
func dedupedMetricProducers(envValue string) []string {
297297
producers := make(map[string]struct{})
298-
for _, producer := range strings.Split(envValue, ",") {
298+
for producer := range strings.SplitSeq(envValue, ",") {
299299
producers[producer] = struct{}{}
300300
}
301301

exporters/autoexport/registry_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,14 @@ func TestRegistryIsConcurrentSafe(t *testing.T) {
4646

4747
var wg sync.WaitGroup
4848

49-
wg.Add(1)
50-
go func() {
51-
defer wg.Done()
49+
wg.Go(func() {
5250
assert.ErrorIs(t, r.store(exporterName, factory("stdout")), errDuplicateRegistration)
53-
}()
51+
})
5452

55-
wg.Add(1)
56-
go func() {
57-
defer wg.Done()
53+
wg.Go(func() {
5854
_, err := r.load(t.Context(), exporterName)
5955
assert.NoError(t, err, "missing exporter in registry")
60-
}()
56+
})
6157

6258
wg.Wait()
6359
}

instrumentation/github.com/aws/aws-lambda-go/otellambda/lambdatest_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ func mockRequestCarrier(eventJSON []byte) propagation.TextMapCarrier {
351351
var event mockRequest
352352
err := json.Unmarshal(eventJSON, &event)
353353
if err != nil {
354-
fmt.Println("event type: ", reflect.TypeOf(event))
354+
fmt.Println("event type: ", reflect.TypeFor[mockRequest]())
355355
panic("mockRequestCarrier only supports events of type mockRequest")
356356
}
357357
return propagation.HeaderCarrier{mockPropagatorKey: []string{event.Headers[mockPropagatorKey]}}
@@ -361,10 +361,10 @@ func mockTraceAttributeFn(eventJSON []byte) []attribute.KeyValue {
361361
var event mockRequest
362362
err := json.Unmarshal(eventJSON, &event)
363363
if err != nil {
364-
fmt.Println("event type: ", reflect.TypeOf(event))
364+
fmt.Println("event type: ", reflect.TypeFor[mockRequest]())
365365
panic("mockRequestCarrier only supports events of type mockRequest")
366366
}
367-
return []attribute.KeyValue{attribute.String("mock.request.type", reflect.TypeOf(event).String())}
367+
return []attribute.KeyValue{attribute.String("mock.request.type", reflect.TypeFor[mockRequest]().String())}
368368
}
369369

370370
func TestInstrumentHandlerTracingWithMockPropagator(t *testing.T) {
@@ -427,6 +427,6 @@ func TestWrapHandlerTracingWithTraceAttributeFn(t *testing.T) {
427427

428428
assert.Len(t, memExporter.GetSpans(), 1)
429429
stub := memExporter.GetSpans()[0]
430-
expectedAttr := attribute.KeyValue{Key: "mock.request.type", Value: attribute.StringValue(reflect.TypeOf(mockPropagatorTestsEvent).String())}
430+
expectedAttr := attribute.KeyValue{Key: "mock.request.type", Value: attribute.StringValue(reflect.TypeFor[mockRequest]().String())}
431431
assert.Contains(t, stub.Attributes, expectedAttr, "custom attribute 'mock.request.type' with value 'otellambda_test.mockRequest' not found")
432432
}

instrumentation/github.com/aws/aws-lambda-go/otellambda/wrapLambdaHandler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func validateArguments(handler reflect.Type) (bool, error) {
3030
if handler.NumIn() > 2 {
3131
return false, fmt.Errorf("handlers may not take more than two arguments, but handler takes %d", handler.NumIn())
3232
} else if handler.NumIn() > 0 {
33-
contextType := reflect.TypeOf((*context.Context)(nil)).Elem()
33+
contextType := reflect.TypeFor[context.Context]()
3434
argumentType := handler.In(0)
3535
handlerTakesContext = argumentType.Implements(contextType)
3636
if handler.NumIn() > 1 && !handlerTakesContext {
@@ -44,7 +44,7 @@ func validateArguments(handler reflect.Type) (bool, error) {
4444
// Ensure handler returns 0-2 values, with an error
4545
// as its first value if any exist.
4646
func validateReturns(handler reflect.Type) error {
47-
errorType := reflect.TypeOf((*error)(nil)).Elem()
47+
errorType := reflect.TypeFor[error]()
4848

4949
switch n := handler.NumOut(); {
5050
case n > 2:

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package xrayconfig
88

99
import (
1010
"sort"
11+
"strings"
1112

1213
collectortracepb "go.opentelemetry.io/proto/otlp/collector/trace/v1"
1314
commonpb "go.opentelemetry.io/proto/otlp/common/v1"
@@ -72,11 +73,11 @@ func (s *SpansStorage) GetResourceSpans() []*tracepb.ResourceSpans {
7273

7374
func resourceString(res *resourcepb.Resource) string {
7475
sAttrs := sortedAttributes(res.GetAttributes())
75-
rstr := ""
76-
for _, attr := range sAttrs {
77-
rstr += attr.String()
76+
strs := make([]string, len(sAttrs))
77+
for i, attr := range sAttrs {
78+
strs[i] = attr.String()
7879
}
79-
return rstr
80+
return strings.Join(strs, "")
8081
}
8182

8283
func sortedAttributes(attrs []*commonpb.KeyValue) []*commonpb.KeyValue {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func WithCommandAttributeDisabled(disabled bool) AttributeOption {
6565
// hasOptIn returns true if the comma-separated version string contains the
6666
// exact optIn value.
6767
func hasOptIn(version, optIn string) bool {
68-
for _, v := range strings.Split(version, ",") {
68+
for v := range strings.SplitSeq(version, ",") {
6969
if strings.TrimSpace(v) == optIn {
7070
return true
7171
}

0 commit comments

Comments
 (0)