Skip to content

Commit

Permalink
[chore]: enable int-conversion rule of perfsprint
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Nov 10, 2024
1 parent ac5caea commit 0d48e02
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ linters:
- govet
- ineffassign
- misspell
- perfsprint
- revive
- staticcheck
- tenv
Expand Down Expand Up @@ -154,6 +155,12 @@ linters-settings:
locale: US
ignore-words:
- cancelled
perfsprint:
err-error: false
errorf: false
int-conversion: true
sprintf1: false
strconcat: false
revive:
# Sets the default failure confidence.
# This means that linting errors with less than 0.8 confidence will be ignored.
Expand Down
7 changes: 4 additions & 3 deletions baggage/baggage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"math/rand"
"slices"
"strconv"
"strings"
"testing"
"unicode/utf8"
Expand Down Expand Up @@ -232,15 +233,15 @@ func TestNewBaggageWithDuplicates(t *testing.T) {
// Duplicates are collapsed.
m[i] = Member{
key: "a",
value: fmt.Sprintf("%d", i),
value: strconv.Itoa(i),
hasData: true,
}
}
b, err := New(m...)
assert.NoError(t, err)

// Ensure that the last-one-wins by verifying the value.
v := fmt.Sprintf("%d", maxMembers)
v := strconv.Itoa(maxMembers)
want := Baggage{list: baggage.List{"a": {Value: v}}}
assert.Equal(t, want, b)
}
Expand Down Expand Up @@ -272,7 +273,7 @@ func TestNewBaggageErrorTooManyBytes(t *testing.T) {
func TestNewBaggageErrorTooManyMembers(t *testing.T) {
m := make([]Member, maxMembers+1)
for i := range m {
m[i] = Member{key: fmt.Sprintf("%d", i), hasData: true}
m[i] = Member{key: strconv.Itoa(i), hasData: true}
}
_, err := New(m...)
assert.ErrorIs(t, err, errMemberNumber)
Expand Down
2 changes: 1 addition & 1 deletion bridge/opencensus/internal/ocmetric/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ func TestConvertKV(t *testing.T) {
},
{
value: uint(math.MaxUint),
expected: attribute.StringValue(fmt.Sprintf("%v", uint(math.MaxUint))),
expected: attribute.StringValue(strconv.FormatUint(uint64(uint(math.MaxUint)), 10)),
},
{
value: []uint{10, 20},
Expand Down
5 changes: 3 additions & 2 deletions bridge/opentracing/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package opentracing // import "go.opentelemetry.io/otel/bridge/opentracing"
import (
"context"
"fmt"
"strconv"
"strings"
"sync"

Expand Down Expand Up @@ -532,7 +533,7 @@ func otTagToOTelAttr(k string, v interface{}) attribute.KeyValue {
case int64:
return key.Int64(val)
case uint64:
return key.String(fmt.Sprintf("%d", val))
return key.String(strconv.FormatUint(val, 10))
case float64:
return key.Float64(val)
case int8:
Expand All @@ -552,7 +553,7 @@ func otTagToOTelAttr(k string, v interface{}) attribute.KeyValue {
case int:
return key.Int(val)
case uint:
return key.String(fmt.Sprintf("%d", val))
return key.String(strconv.FormatUint(uint64(val), 10))
case string:
return key.String(val)
default:
Expand Down
4 changes: 2 additions & 2 deletions codes/codes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package codes
import (
"bytes"
"encoding/json"
"fmt"
"strconv"
"testing"
)

Expand Down Expand Up @@ -72,7 +72,7 @@ func TestCodeUnmarshalJSON(t *testing.T) {

func TestCodeUnmarshalJSONErrorInvalidData(t *testing.T) {
tests := []string{
fmt.Sprintf("%d", maxCode),
strconv.Itoa(maxCode),
"Not a code",
"Unset",
"true",
Expand Down
3 changes: 2 additions & 1 deletion exporters/zipkin/internal/internaltest/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package internaltest // import "go.opentelemetry.io/otel/exporters/zipkin/intern
import (
"context"
"fmt"
"strconv"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -58,7 +59,7 @@ func (h *Harness) TestTracerProvider(subjectFactory func() trace.TracerProvider)
go func(name, version string) {
_ = tp.Tracer(name, trace.WithInstrumentationVersion(version))
wg.Done()
}(fmt.Sprintf("tracer %d", i%5), fmt.Sprintf("%d", i))
}(fmt.Sprintf("tracer %d", i%5), strconv.Itoa(i))
}
wg.Wait()
done <- struct{}{}
Expand Down
3 changes: 2 additions & 1 deletion internal/internaltest/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package internaltest // import "go.opentelemetry.io/otel/internal/internaltest"
import (
"context"
"fmt"
"strconv"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -58,7 +59,7 @@ func (h *Harness) TestTracerProvider(subjectFactory func() trace.TracerProvider)
go func(name, version string) {
_ = tp.Tracer(name, trace.WithInstrumentationVersion(version))
wg.Done()
}(fmt.Sprintf("tracer %d", i%5), fmt.Sprintf("%d", i))
}(fmt.Sprintf("tracer %d", i%5), strconv.Itoa(i))
}
wg.Wait()
done <- struct{}{}
Expand Down
3 changes: 2 additions & 1 deletion internal/shared/internaltest/harness.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package internaltest
import (
"context"
"fmt"
"strconv"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -58,7 +59,7 @@ func (h *Harness) TestTracerProvider(subjectFactory func() trace.TracerProvider)
go func(name, version string) {
_ = tp.Tracer(name, trace.WithInstrumentationVersion(version))
wg.Done()
}(fmt.Sprintf("tracer %d", i%5), fmt.Sprintf("%d", i))
}(fmt.Sprintf("tracer %d", i%5), strconv.Itoa(i))
}
wg.Wait()
done <- struct{}{}
Expand Down
3 changes: 2 additions & 1 deletion sdk/internal/internaltest/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package internaltest // import "go.opentelemetry.io/otel/sdk/internal/internalte
import (
"context"
"fmt"
"strconv"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -58,7 +59,7 @@ func (h *Harness) TestTracerProvider(subjectFactory func() trace.TracerProvider)
go func(name, version string) {
_ = tp.Tracer(name, trace.WithInstrumentationVersion(version))
wg.Done()
}(fmt.Sprintf("tracer %d", i%5), fmt.Sprintf("%d", i))
}(fmt.Sprintf("tracer %d", i%5), strconv.Itoa(i))
}
wg.Wait()
done <- struct{}{}
Expand Down
5 changes: 3 additions & 2 deletions sdk/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"os"
"strconv"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -560,7 +561,7 @@ func TestWithProcessPID(t *testing.T) {

require.NoError(t, err)
require.EqualValues(t, map[string]string{
"process.pid": fmt.Sprint(fakePID),
"process.pid": strconv.Itoa(fakePID),
}, toMap(res))
}

Expand Down Expand Up @@ -674,7 +675,7 @@ func TestWithProcess(t *testing.T) {
require.NoError(t, err)
jsonCommandArgs, _ := json.Marshal(fakeCommandArgs)
require.EqualValues(t, map[string]string{
"process.pid": fmt.Sprint(fakePID),
"process.pid": strconv.Itoa(fakePID),
"process.executable.name": fakeExecutableName,
"process.executable.path": fakeExecutablePath,
"process.command_args": string(jsonCommandArgs),
Expand Down

0 comments on commit 0d48e02

Please sign in to comment.