Skip to content

Commit 7c914b9

Browse files
authored
[chore]: enable gofumpt linter for pkg (#36348)
#### Description [gofumpt](https://golangci-lint.run/usage/linters/#gofumpt) enforces a stricter format than gofmt Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 7281556 commit 7c914b9

File tree

89 files changed

+339
-280
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+339
-280
lines changed

pkg/golden/golden.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func writeMetrics(filePath string, metrics pmetric.Metrics, opts ...WriteMetrics
8686
if err != nil {
8787
return err
8888
}
89-
return os.WriteFile(filePath, b, 0600)
89+
return os.WriteFile(filePath, b, 0o600)
9090
}
9191

9292
// ReadLogs reads a plog.Logs from the specified YAML or JSON file.
@@ -137,7 +137,7 @@ func writeLogs(filePath string, logs plog.Logs) error {
137137
if err := enc.Encode(jsonVal); err != nil {
138138
return err
139139
}
140-
return os.WriteFile(filePath, b.Bytes(), 0600)
140+
return os.WriteFile(filePath, b.Bytes(), 0o600)
141141
}
142142

143143
// ReadTraces reads a ptrace.Traces from the specified YAML or JSON file.
@@ -188,5 +188,5 @@ func writeTraces(filePath string, traces ptrace.Traces) error {
188188
if err := enc.Encode(jsonVal); err != nil {
189189
return err
190190
}
191-
return os.WriteFile(filePath, b.Bytes(), 0600)
191+
return os.WriteFile(filePath, b.Bytes(), 0o600)
192192
}

pkg/golden/golden_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func testMetrics() pmetric.MetricSlice {
141141

142142
dp = dps.AppendEmpty()
143143
attributes = pcommon.NewMap()
144-
setDPDoubleVal(dp, 2, attributes, time.Date(1997, 07, 27, 1, 1, 1, 1, &time.Location{}))
144+
setDPDoubleVal(dp, 2, attributes, time.Date(1997, 0o7, 27, 1, 1, 1, 1, &time.Location{}))
145145
return slice
146146
}
147147

pkg/ottl/boolean_value_test.go

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func Test_newComparisonEvaluator(t *testing.T) {
115115

116116
JanFirst2023 := time.Date(2023, 1, 1, 0, 0, 0, 0, time.Local)
117117

118-
var tests = []struct {
118+
tests := []struct {
119119
name string
120120
l any
121121
r any
@@ -159,16 +159,16 @@ func Test_newComparisonEvaluator(t *testing.T) {
159159
{name: "compare not greater than equal to durations", l: "dur1", r: "dur2", op: ">=", want: false, item: map[string]time.Duration{"dur1": oneMillisecond, "dur2": threeSeconds}},
160160
{name: "compare equal times", l: "time1", r: "time2", op: "==", want: true, item: map[string]time.Time{"time1": JanFirst2023, "time2": JanFirst2023}},
161161
{name: "compare unequal times", l: "time1", r: "time2", op: "==", want: false, item: map[string]time.Time{"time1": JanFirst2023, "time2": time.Date(2023, 1, 2, 0, 0, 0, 0, time.Local)}},
162-
{name: "compare for not equal times", l: "time1", r: "time2", op: "!=", want: true, item: map[string]time.Time{"time1": JanFirst2023, "time2": time.Date(2002, 11, 2, 01, 01, 01, 01, time.Local)}},
163-
{name: "compare for equal times using not equal", l: "time1", r: "time2", op: "!=", want: false, item: map[string]time.Time{"time1": time.Date(2002, 11, 2, 01, 01, 01, 01, time.Local), "time2": time.Date(2002, 11, 2, 01, 01, 01, 01, time.Local)}},
164-
{name: "compare less than times", l: "time1", r: "time2", op: "<", want: true, item: map[string]time.Time{"time1": JanFirst2023, "time2": time.Date(2023, 5, 2, 01, 01, 01, 01, time.Local)}},
165-
{name: "compare not less than times", l: "time1", r: "time2", op: "<", want: false, item: map[string]time.Time{"time1": time.Date(2023, 6, 2, 01, 01, 01, 01, time.Local), "time2": time.Date(2023, 5, 2, 01, 01, 01, 01, time.Local)}},
166-
{name: "compare less than equal to times", l: "time1", r: "time2", op: "<=", want: true, item: map[string]time.Time{"time1": time.Date(2003, 5, 2, 01, 01, 01, 01, time.Local), "time2": time.Date(2003, 5, 2, 01, 01, 01, 01, time.Local)}},
167-
{name: "compare not less than equal to times", l: "time1", r: "time2", op: "<=", want: false, item: map[string]time.Time{"time1": time.Date(2002, 5, 2, 01, 01, 01, 01, time.Local), "time2": time.Date(1999, 5, 2, 01, 01, 01, 01, time.Local)}},
168-
{name: "compare not greater than equal to w/ times", l: "time1", r: "time2", op: ">=", want: false, item: map[string]time.Time{"time1": time.Date(2002, 5, 2, 01, 01, 01, 01, time.Local), "time2": time.Date(2003, 5, 2, 01, 01, 01, 01, time.Local)}},
169-
{name: "compare greater than equal to w/ times", l: "time1", r: "time2", op: ">=", want: true, item: map[string]time.Time{"time1": time.Date(2022, 5, 2, 01, 01, 01, 01, time.Local), "time2": time.Date(2003, 5, 2, 01, 01, 01, 01, time.Local)}},
170-
{name: "compare greater than w/ times", l: "time1", r: "time2", op: ">", want: true, item: map[string]time.Time{"time1": time.Date(2022, 5, 2, 01, 01, 01, 01, time.Local), "time2": time.Date(2003, 5, 2, 01, 01, 01, 01, time.Local)}},
171-
{name: "compare not greater than w/ times", l: "time1", r: "time2", op: ">", want: false, item: map[string]time.Time{"time1": time.Date(2002, 3, 2, 01, 01, 01, 01, time.Local), "time2": time.Date(2003, 5, 2, 01, 01, 01, 01, time.Local)}},
162+
{name: "compare for not equal times", l: "time1", r: "time2", op: "!=", want: true, item: map[string]time.Time{"time1": JanFirst2023, "time2": time.Date(2002, 11, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
163+
{name: "compare for equal times using not equal", l: "time1", r: "time2", op: "!=", want: false, item: map[string]time.Time{"time1": time.Date(2002, 11, 2, 0o1, 0o1, 0o1, 0o1, time.Local), "time2": time.Date(2002, 11, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
164+
{name: "compare less than times", l: "time1", r: "time2", op: "<", want: true, item: map[string]time.Time{"time1": JanFirst2023, "time2": time.Date(2023, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
165+
{name: "compare not less than times", l: "time1", r: "time2", op: "<", want: false, item: map[string]time.Time{"time1": time.Date(2023, 6, 2, 0o1, 0o1, 0o1, 0o1, time.Local), "time2": time.Date(2023, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
166+
{name: "compare less than equal to times", l: "time1", r: "time2", op: "<=", want: true, item: map[string]time.Time{"time1": time.Date(2003, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local), "time2": time.Date(2003, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
167+
{name: "compare not less than equal to times", l: "time1", r: "time2", op: "<=", want: false, item: map[string]time.Time{"time1": time.Date(2002, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local), "time2": time.Date(1999, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
168+
{name: "compare not greater than equal to w/ times", l: "time1", r: "time2", op: ">=", want: false, item: map[string]time.Time{"time1": time.Date(2002, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local), "time2": time.Date(2003, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
169+
{name: "compare greater than equal to w/ times", l: "time1", r: "time2", op: ">=", want: true, item: map[string]time.Time{"time1": time.Date(2022, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local), "time2": time.Date(2003, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
170+
{name: "compare greater than w/ times", l: "time1", r: "time2", op: ">", want: true, item: map[string]time.Time{"time1": time.Date(2022, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local), "time2": time.Date(2003, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
171+
{name: "compare not greater than w/ times", l: "time1", r: "time2", op: ">", want: false, item: map[string]time.Time{"time1": time.Date(2002, 3, 2, 0o1, 0o1, 0o1, 0o1, time.Local), "time2": time.Date(2003, 5, 2, 0o1, 0o1, 0o1, 0o1, time.Local)}},
172172
}
173173
for _, tt := range tests {
174174
t.Run(tt.name, func(t *testing.T) {
@@ -220,6 +220,7 @@ func True() (ExprFunc[any], error) {
220220
return true, nil
221221
}, nil
222222
}
223+
223224
func False() (ExprFunc[any], error) {
224225
return func(_ context.Context, _ any) (any, error) {
225226
return false, nil
@@ -243,7 +244,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
243244
want bool
244245
expr *booleanExpression
245246
}{
246-
{"a", false,
247+
{
248+
"a", false,
247249
&booleanExpression{
248250
Left: &term{
249251
Left: &booleanValue{
@@ -264,7 +266,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
264266
},
265267
},
266268
},
267-
{"b", true,
269+
{
270+
"b", true,
268271
&booleanExpression{
269272
Left: &term{
270273
Left: &booleanValue{
@@ -285,7 +288,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
285288
},
286289
},
287290
},
288-
{"c", false,
291+
{
292+
"c", false,
289293
&booleanExpression{
290294
Left: &term{
291295
Left: &booleanValue{
@@ -314,7 +318,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
314318
},
315319
},
316320
},
317-
{"d", true,
321+
{
322+
"d", true,
318323
&booleanExpression{
319324
Left: &term{
320325
Left: &booleanValue{
@@ -337,7 +342,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
337342
},
338343
},
339344
},
340-
{"e", true,
345+
{
346+
"e", true,
341347
&booleanExpression{
342348
Left: &term{
343349
Left: &booleanValue{
@@ -360,7 +366,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
360366
},
361367
},
362368
},
363-
{"f", false,
369+
{
370+
"f", false,
364371
&booleanExpression{
365372
Left: &term{
366373
Left: &booleanValue{
@@ -383,7 +390,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
383390
},
384391
},
385392
},
386-
{"g", true,
393+
{
394+
"g", true,
387395
&booleanExpression{
388396
Left: &term{
389397
Left: &booleanValue{
@@ -416,7 +424,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
416424
},
417425
},
418426
},
419-
{"h", true,
427+
{
428+
"h", true,
420429
&booleanExpression{
421430
Left: &term{
422431
Left: &booleanValue{
@@ -455,7 +464,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
455464
},
456465
},
457466
},
458-
{"i", true,
467+
{
468+
"i", true,
459469
&booleanExpression{
460470
Left: &term{
461471
Left: &booleanValue{
@@ -467,7 +477,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
467477
},
468478
},
469479
},
470-
{"j", false,
480+
{
481+
"j", false,
471482
&booleanExpression{
472483
Left: &term{
473484
Left: &booleanValue{
@@ -479,7 +490,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
479490
},
480491
},
481492
},
482-
{"k", true,
493+
{
494+
"k", true,
483495
&booleanExpression{
484496
Left: &term{
485497
Left: &booleanValue{
@@ -497,7 +509,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
497509
},
498510
},
499511
},
500-
{"l", false,
512+
{
513+
"l", false,
501514
&booleanExpression{
502515
Left: &term{
503516
Left: &booleanValue{
@@ -537,7 +550,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
537550
},
538551
},
539552
},
540-
{"m", false,
553+
{
554+
"m", false,
541555
&booleanExpression{
542556
Left: &term{
543557
Left: &booleanValue{
@@ -573,7 +587,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
573587
},
574588
},
575589
},
576-
{"n", true,
590+
{
591+
"n", true,
577592
&booleanExpression{
578593
Left: &term{
579594
Left: &booleanValue{
@@ -586,7 +601,8 @@ func Test_newBooleanExpressionEvaluator(t *testing.T) {
586601
},
587602
},
588603
},
589-
{"o", false,
604+
{
605+
"o", false,
590606
&booleanExpression{
591607
Left: &term{
592608
Left: &booleanValue{

pkg/ottl/context_inferrer.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@ package ottl // import "github.com/open-telemetry/opentelemetry-collector-contri
55

66
import "math"
77

8-
var (
9-
defaultContextInferPriority = []string{
10-
"log",
11-
"metric",
12-
"datapoint",
13-
"spanevent",
14-
"span",
15-
"resource",
16-
"scope",
17-
"instrumentation_scope",
18-
}
19-
)
8+
var defaultContextInferPriority = []string{
9+
"log",
10+
"metric",
11+
"datapoint",
12+
"spanevent",
13+
"span",
14+
"resource",
15+
"scope",
16+
"instrumentation_scope",
17+
}
2018

2119
// contextInferrer is an interface used to infer the OTTL context from statements paths.
2220
type contextInferrer interface {

pkg/ottl/contexts/ottldatapoint/datapoint.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ const (
2323
contextName = "DataPoint"
2424
)
2525

26-
var _ internal.ResourceContext = (*TransformContext)(nil)
27-
var _ internal.InstrumentationScopeContext = (*TransformContext)(nil)
28-
var _ zapcore.ObjectMarshaler = (*TransformContext)(nil)
26+
var (
27+
_ internal.ResourceContext = (*TransformContext)(nil)
28+
_ internal.InstrumentationScopeContext = (*TransformContext)(nil)
29+
_ zapcore.ObjectMarshaler = (*TransformContext)(nil)
30+
)
2931

3032
type TransformContext struct {
3133
dataPoint any

pkg/ottl/contexts/ottllog/log.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ const (
2525
contextName = "Log"
2626
)
2727

28-
var _ internal.ResourceContext = (*TransformContext)(nil)
29-
var _ internal.InstrumentationScopeContext = (*TransformContext)(nil)
30-
var _ zapcore.ObjectMarshaler = (*TransformContext)(nil)
28+
var (
29+
_ internal.ResourceContext = (*TransformContext)(nil)
30+
_ internal.InstrumentationScopeContext = (*TransformContext)(nil)
31+
_ zapcore.ObjectMarshaler = (*TransformContext)(nil)
32+
)
3133

3234
type TransformContext struct {
3335
logRecord plog.LogRecord

pkg/ottl/contexts/ottlmetric/metrics.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import (
1515
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal"
1616
)
1717

18-
var _ internal.ResourceContext = TransformContext{}
19-
var _ internal.InstrumentationScopeContext = TransformContext{}
20-
var _ internal.MetricContext = TransformContext{}
18+
var (
19+
_ internal.ResourceContext = TransformContext{}
20+
_ internal.InstrumentationScopeContext = TransformContext{}
21+
_ internal.MetricContext = TransformContext{}
22+
)
2123

2224
type TransformContext struct {
2325
metric pmetric.Metric

pkg/ottl/contexts/ottlresource/resource.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ import (
1717
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging"
1818
)
1919

20-
var _ internal.ResourceContext = (*TransformContext)(nil)
21-
var _ zapcore.ObjectMarshaler = (*TransformContext)(nil)
20+
var (
21+
_ internal.ResourceContext = (*TransformContext)(nil)
22+
_ zapcore.ObjectMarshaler = (*TransformContext)(nil)
23+
)
2224

2325
type TransformContext struct {
2426
resource pcommon.Resource

pkg/ottl/contexts/ottlscope/scope.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ import (
1717
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging"
1818
)
1919

20-
var _ internal.ResourceContext = (*TransformContext)(nil)
21-
var _ internal.InstrumentationScopeContext = (*TransformContext)(nil)
22-
var _ zapcore.ObjectMarshaler = (*TransformContext)(nil)
20+
var (
21+
_ internal.ResourceContext = (*TransformContext)(nil)
22+
_ internal.InstrumentationScopeContext = (*TransformContext)(nil)
23+
_ zapcore.ObjectMarshaler = (*TransformContext)(nil)
24+
)
2325

2426
type TransformContext struct {
2527
instrumentationScope pcommon.InstrumentationScope

pkg/ottl/contexts/ottlspan/span.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ import (
1818
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/internal/logging"
1919
)
2020

21-
var _ internal.ResourceContext = (*TransformContext)(nil)
22-
var _ internal.InstrumentationScopeContext = (*TransformContext)(nil)
23-
var _ zapcore.ObjectMarshaler = (*TransformContext)(nil)
21+
var (
22+
_ internal.ResourceContext = (*TransformContext)(nil)
23+
_ internal.InstrumentationScopeContext = (*TransformContext)(nil)
24+
_ zapcore.ObjectMarshaler = (*TransformContext)(nil)
25+
)
2426

2527
type TransformContext struct {
2628
span ptrace.Span

0 commit comments

Comments
 (0)