Skip to content

Commit

Permalink
[chore]: enable all rules of perfsprint
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
  • Loading branch information
mmorel-35 committed Nov 14, 2024
1 parent 61e9b35 commit 8a5fa3f
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 38 deletions.
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ linters-settings:
ignore-words:
- cancelled
perfsprint:
err-error: false
errorf: false
err-error: true
errorf: true
int-conversion: true
sprintf1: false
strconcat: false
sprintf1: true
strconcat: true
revive:
# Sets the default failure confidence.
# This means that linting errors with less than 0.8 confidence will be ignored.
Expand Down
2 changes: 1 addition & 1 deletion bridge/opencensus/internal/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ func (s *Span) AddLink(l octrace.Link) {

// String prints a string representation of this span.
func (s *Span) String() string {
return fmt.Sprintf("span %s", s.otelSpan.SpanContext().SpanID().String())
return "span " + s.otelSpan.SpanContext().SpanID().String()
}
3 changes: 2 additions & 1 deletion codes/codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package codes // import "go.opentelemetry.io/otel/codes"

import (
"encoding/json"
"errors"
"fmt"
"strconv"
)
Expand Down Expand Up @@ -63,7 +64,7 @@ func (c *Code) UnmarshalJSON(b []byte) error {
return nil
}
if c == nil {
return fmt.Errorf("nil receiver passed to UnmarshalJSON")
return errors.New("nil receiver passed to UnmarshalJSON")
}

var x interface{}
Expand Down
3 changes: 2 additions & 1 deletion exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package otlpmetricgrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlpme

import (
"context"
"errors"
"fmt"
"sync"

Expand Down Expand Up @@ -114,7 +115,7 @@ func (e *Exporter) Shutdown(ctx context.Context) error {
return err
}

var errShutdown = fmt.Errorf("gRPC exporter is shutdown")
var errShutdown = errors.New("gRPC exporter is shutdown")

type shutdownClient struct{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func cleanPath(urlPath string, defaultPath string) string {
return defaultPath
}
if !path.IsAbs(tmp) {
tmp = fmt.Sprintf("/%s", tmp)
tmp = "/" + tmp
}
return tmp
}
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlpmetric/otlpmetrichttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func newResponseError(header http.Header, wrapped error) error {

func (e retryableError) Error() string {
if e.err != nil {
return fmt.Sprintf("retry-able request failure: %s", e.err.Error())
return "retry-able request failure: " + e.err.Error()
}

return "retry-able request failure"
Expand Down
3 changes: 2 additions & 1 deletion exporters/otlp/otlpmetric/otlpmetrichttp/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package otlpmetrichttp // import "go.opentelemetry.io/otel/exporters/otlp/otlpme

import (
"context"
"errors"
"fmt"
"sync"

Expand Down Expand Up @@ -114,7 +115,7 @@ func (e *Exporter) Shutdown(ctx context.Context) error {
return err
}

var errShutdown = fmt.Errorf("HTTP exporter is shutdown")
var errShutdown = errors.New("HTTP exporter is shutdown")

type shutdownClient struct{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func cleanPath(urlPath string, defaultPath string) string {
return defaultPath
}
if !path.IsAbs(tmp) {
tmp = fmt.Sprintf("/%s", tmp)
tmp = "/" + tmp
}
return tmp
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func cleanPath(urlPath string, defaultPath string) string {
return defaultPath
}
if !path.IsAbs(tmp) {
tmp = fmt.Sprintf("/%s", tmp)
tmp = "/" + tmp
}
return tmp
}
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlptrace/otlptracehttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func newResponseError(header http.Header, wrapped error) error {

func (e retryableError) Error() string {
if e.err != nil {
return fmt.Sprintf("retry-able request failure: %s", e.err.Error())
return "retry-able request failure: " + e.err.Error()
}

return "retry-able request failure"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func cleanPath(urlPath string, defaultPath string) string {
return defaultPath
}
if !path.IsAbs(tmp) {
tmp = fmt.Sprintf("/%s", tmp)
tmp = "/" + tmp
}
return tmp
}
Expand Down
2 changes: 1 addition & 1 deletion internal/shared/otlp/otlpmetric/oconf/options.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func cleanPath(urlPath string, defaultPath string) string {
return defaultPath
}
if !path.IsAbs(tmp) {
tmp = fmt.Sprintf("/%s", tmp)
tmp = "/" + tmp
}
return tmp
}
Expand Down
2 changes: 1 addition & 1 deletion internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func cleanPath(urlPath string, defaultPath string) string {
return defaultPath
}
if !path.IsAbs(tmp) {
tmp = fmt.Sprintf("/%s", tmp)
tmp = "/" + tmp
}
return tmp
}
Expand Down
4 changes: 2 additions & 2 deletions sdk/metric/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ package metric // import "go.opentelemetry.io/otel/sdk/metric"

import (
"context"
"fmt"
"errors"

"go.opentelemetry.io/otel/sdk/metric/metricdata"
)

// ErrExporterShutdown is returned if Export or Shutdown are called after an
// Exporter has been Shutdown.
var ErrExporterShutdown = fmt.Errorf("exporter is shutdown")
var ErrExporterShutdown = errors.New("exporter is shutdown")

// Exporter handles the delivery of metric data to external receivers. This is
// the final component in the metric push pipeline.
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func (m *meter) RegisterCallback(f metric.Callback, insts ...metric.Observable)
validInstruments = append(validInstruments, inst)
default:
// Instrument external to the SDK.
return nil, fmt.Errorf("invalid observable: from different implementation")
return nil, errors.New("invalid observable: from different implementation")
}
}

Expand Down
22 changes: 11 additions & 11 deletions sdk/metric/metricdata/metricdatatest/comparisons.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func equalResourceMetrics(a, b metricdata.ResourceMetrics, cfg config) (reasons
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("ResourceMetrics ScopeMetrics not equal:\n%s", r))
reasons = append(reasons, "ResourceMetrics ScopeMetrics not equal:\n"+r)
}
return reasons
}
Expand All @@ -56,7 +56,7 @@ func equalScopeMetrics(a, b metricdata.ScopeMetrics, cfg config) (reasons []stri
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("ScopeMetrics Metrics not equal:\n%s", r))
reasons = append(reasons, "ScopeMetrics Metrics not equal:\n"+r)
}
return reasons
}
Expand Down Expand Up @@ -172,7 +172,7 @@ func equalGauges[N int64 | float64](a, b metricdata.Gauge[N], cfg config) (reaso
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("Gauge DataPoints not equal:\n%s", r))
reasons = append(reasons, "Gauge DataPoints not equal:\n"+r)
}
return reasons
}
Expand All @@ -199,7 +199,7 @@ func equalSums[N int64 | float64](a, b metricdata.Sum[N], cfg config) (reasons [
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("Sum DataPoints not equal:\n%s", r))
reasons = append(reasons, "Sum DataPoints not equal:\n"+r)
}
return reasons
}
Expand All @@ -223,7 +223,7 @@ func equalHistograms[N int64 | float64](a, b metricdata.Histogram[N], cfg config
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("Histogram DataPoints not equal:\n%s", r))
reasons = append(reasons, "Histogram DataPoints not equal:\n"+r)
}
return reasons
}
Expand Down Expand Up @@ -264,7 +264,7 @@ func equalDataPoints[N int64 | float64](a, b metricdata.DataPoint[N], cfg config
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("Exemplars not equal:\n%s", r))
reasons = append(reasons, "Exemplars not equal:\n"+r)
}
}
return reasons
Expand Down Expand Up @@ -318,7 +318,7 @@ func equalHistogramDataPoints[N int64 | float64](a, b metricdata.HistogramDataPo
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("Exemplars not equal:\n%s", r))
reasons = append(reasons, "Exemplars not equal:\n"+r)
}
}
return reasons
Expand All @@ -343,7 +343,7 @@ func equalExponentialHistograms[N int64 | float64](a, b metricdata.ExponentialHi
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("Histogram DataPoints not equal:\n%s", r))
reasons = append(reasons, "Histogram DataPoints not equal:\n"+r)
}
return reasons
}
Expand Down Expand Up @@ -406,7 +406,7 @@ func equalExponentialHistogramDataPoints[N int64 | float64](a, b metricdata.Expo
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("Exemplars not equal:\n%s", r))
reasons = append(reasons, "Exemplars not equal:\n"+r)
}
}
return reasons
Expand All @@ -432,7 +432,7 @@ func equalSummary(a, b metricdata.Summary, cfg config) (reasons []string) {
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("Summary DataPoints not equal:\n%s", r))
reasons = append(reasons, "Summary DataPoints not equal:\n"+r)
}
return reasons
}
Expand Down Expand Up @@ -634,7 +634,7 @@ func compareDiff[T any](extraExpected, extraActual []T) string {
}

func missingAttrStr(name string) string {
return fmt.Sprintf("missing attribute %s", name)
return "missing attribute " + name
}

func hasAttributesExemplars[T int64 | float64](exemplar metricdata.Exemplar[T], attrs ...attribute.KeyValue) (reasons []string) {
Expand Down
10 changes: 5 additions & 5 deletions sdk/metric/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ package metric // import "go.opentelemetry.io/otel/sdk/metric"

import (
"context"
"fmt"
"errors"

"go.opentelemetry.io/otel/sdk/metric/metricdata"
)

// errDuplicateRegister is logged by a Reader when an attempt to registered it
// more than once occurs.
var errDuplicateRegister = fmt.Errorf("duplicate reader registration")
var errDuplicateRegister = errors.New("duplicate reader registration")

// ErrReaderNotRegistered is returned if Collect or Shutdown are called before
// the reader is registered with a MeterProvider.
var ErrReaderNotRegistered = fmt.Errorf("reader is not registered")
var ErrReaderNotRegistered = errors.New("reader is not registered")

// ErrReaderShutdown is returned if Collect or Shutdown are called after a
// reader has been Shutdown once.
var ErrReaderShutdown = fmt.Errorf("reader is shutdown")
var ErrReaderShutdown = errors.New("reader is shutdown")

// errNonPositiveDuration is logged when an environmental variable
// has non-positive value.
var errNonPositiveDuration = fmt.Errorf("non-positive duration")
var errNonPositiveDuration = errors.New("non-positive duration")

// Reader is the interface used between the SDK and an
// exporter. Control flow is bi-directional through the
Expand Down
5 changes: 2 additions & 3 deletions sdk/trace/sampler_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package trace // import "go.opentelemetry.io/otel/sdk/trace"

import (
"errors"
"fmt"
"os"
"strconv"
"strings"
Expand All @@ -26,7 +25,7 @@ const (
type errUnsupportedSampler string

func (e errUnsupportedSampler) Error() string {
return fmt.Sprintf("unsupported sampler: %s", string(e))
return "unsupported sampler: " + string(e)
}

var (
Expand All @@ -39,7 +38,7 @@ type samplerArgParseError struct {
}

func (e samplerArgParseError) Error() string {
return fmt.Sprintf("parsing sampler argument: %s", e.parseErr.Error())
return "parsing sampler argument: " + e.parseErr.Error()
}

func (e samplerArgParseError) Unwrap() error {
Expand Down

0 comments on commit 8a5fa3f

Please sign in to comment.