You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-09-16 09:26:25 +02:00
Add unparam linter (#5531)
This adds the [unparam](https://github.com/mvdan/unparam) linter. Co-authored-by: Sam Xie <sam@samxie.me> Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
This commit is contained in:
@@ -25,6 +25,7 @@ linters:
|
|||||||
- typecheck
|
- typecheck
|
||||||
- unconvert
|
- unconvert
|
||||||
- unused
|
- unused
|
||||||
|
- unparam
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
# Maximum issues count per one linter.
|
# Maximum issues count per one linter.
|
||||||
|
@@ -29,7 +29,7 @@ type config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newConfig creates a validated Config configured with options.
|
// newConfig creates a validated Config configured with options.
|
||||||
func newConfig(options ...Option) (config, error) {
|
func newConfig(options ...Option) config {
|
||||||
cfg := config{
|
cfg := config{
|
||||||
Writer: defaultWriter,
|
Writer: defaultWriter,
|
||||||
PrettyPrint: defaultPrettyPrint,
|
PrettyPrint: defaultPrettyPrint,
|
||||||
@@ -38,7 +38,7 @@ func newConfig(options ...Option) (config, error) {
|
|||||||
for _, opt := range options {
|
for _, opt := range options {
|
||||||
cfg = opt.apply(cfg)
|
cfg = opt.apply(cfg)
|
||||||
}
|
}
|
||||||
return cfg, nil
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option sets the value of an option for a Config.
|
// Option sets the value of an option for a Config.
|
||||||
|
@@ -19,10 +19,7 @@ var _ trace.SpanExporter = &Exporter{}
|
|||||||
|
|
||||||
// New creates an Exporter with the passed options.
|
// New creates an Exporter with the passed options.
|
||||||
func New(options ...Option) (*Exporter, error) {
|
func New(options ...Option) (*Exporter, error) {
|
||||||
cfg, err := newConfig(options...)
|
cfg := newConfig(options...)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
enc := json.NewEncoder(cfg.Writer)
|
enc := json.NewEncoder(cfg.Writer)
|
||||||
if cfg.PrettyPrint {
|
if cfg.PrettyPrint {
|
||||||
|
@@ -131,9 +131,9 @@ func TestEmptyGroupsPreserved(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBool(t *testing.T) {
|
func TestBool(t *testing.T) {
|
||||||
const key, val = "key", true
|
const key, val = "boolKey", true
|
||||||
kv := log.Bool(key, val)
|
kv := log.Bool(key, val)
|
||||||
testKV(t, key, val, kv)
|
testKV(t, key, kv)
|
||||||
|
|
||||||
v, k := kv.Value, log.KindBool
|
v, k := kv.Value, log.KindBool
|
||||||
t.Run("AsBool", func(t *testing.T) {
|
t.Run("AsBool", func(t *testing.T) {
|
||||||
@@ -148,9 +148,9 @@ func TestBool(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFloat64(t *testing.T) {
|
func TestFloat64(t *testing.T) {
|
||||||
const key, val = "key", 3.0
|
const key, val = "float64Key", 3.0
|
||||||
kv := log.Float64(key, val)
|
kv := log.Float64(key, val)
|
||||||
testKV(t, key, val, kv)
|
testKV(t, key, kv)
|
||||||
|
|
||||||
v, k := kv.Value, log.KindFloat64
|
v, k := kv.Value, log.KindFloat64
|
||||||
t.Run("AsBool", testErrKind(v.AsBool, "AsBool", k))
|
t.Run("AsBool", testErrKind(v.AsBool, "AsBool", k))
|
||||||
@@ -165,9 +165,9 @@ func TestFloat64(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInt(t *testing.T) {
|
func TestInt(t *testing.T) {
|
||||||
const key, val = "key", 1
|
const key, val = "intKey", 1
|
||||||
kv := log.Int(key, val)
|
kv := log.Int(key, val)
|
||||||
testKV[int64](t, key, val, kv)
|
testKV(t, key, kv)
|
||||||
|
|
||||||
v, k := kv.Value, log.KindInt64
|
v, k := kv.Value, log.KindInt64
|
||||||
t.Run("AsBool", testErrKind(v.AsBool, "AsBool", k))
|
t.Run("AsBool", testErrKind(v.AsBool, "AsBool", k))
|
||||||
@@ -182,9 +182,9 @@ func TestInt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestInt64(t *testing.T) {
|
func TestInt64(t *testing.T) {
|
||||||
const key, val = "key", 1
|
const key, val = "int64Key", 1
|
||||||
kv := log.Int64(key, val)
|
kv := log.Int64(key, val)
|
||||||
testKV[int64](t, key, val, kv)
|
testKV(t, key, kv)
|
||||||
|
|
||||||
v, k := kv.Value, log.KindInt64
|
v, k := kv.Value, log.KindInt64
|
||||||
t.Run("AsBool", testErrKind(v.AsBool, "AsBool", k))
|
t.Run("AsBool", testErrKind(v.AsBool, "AsBool", k))
|
||||||
@@ -199,9 +199,9 @@ func TestInt64(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestString(t *testing.T) {
|
func TestString(t *testing.T) {
|
||||||
const key, val = "key", "test string value"
|
const key, val = "stringKey", "test string value"
|
||||||
kv := log.String(key, val)
|
kv := log.String(key, val)
|
||||||
testKV(t, key, val, kv)
|
testKV(t, key, kv)
|
||||||
|
|
||||||
v, k := kv.Value, log.KindString
|
v, k := kv.Value, log.KindString
|
||||||
t.Run("AsBool", testErrKind(v.AsBool, "AsBool", k))
|
t.Run("AsBool", testErrKind(v.AsBool, "AsBool", k))
|
||||||
@@ -216,10 +216,10 @@ func TestString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestBytes(t *testing.T) {
|
func TestBytes(t *testing.T) {
|
||||||
const key = "key"
|
const key = "bytesKey"
|
||||||
val := []byte{3, 2, 1}
|
val := []byte{3, 2, 1}
|
||||||
kv := log.Bytes(key, val)
|
kv := log.Bytes(key, val)
|
||||||
testKV(t, key, val, kv)
|
testKV(t, key, kv)
|
||||||
|
|
||||||
v, k := kv.Value, log.KindBytes
|
v, k := kv.Value, log.KindBytes
|
||||||
t.Run("AsBool", testErrKind(v.AsBool, "AsBool", k))
|
t.Run("AsBool", testErrKind(v.AsBool, "AsBool", k))
|
||||||
@@ -234,10 +234,10 @@ func TestBytes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSlice(t *testing.T) {
|
func TestSlice(t *testing.T) {
|
||||||
const key = "key"
|
const key = "sliceKey"
|
||||||
val := []log.Value{log.IntValue(3), log.StringValue("foo")}
|
val := []log.Value{log.IntValue(3), log.StringValue("foo")}
|
||||||
kv := log.Slice(key, val...)
|
kv := log.Slice(key, val...)
|
||||||
testKV(t, key, val, kv)
|
testKV(t, key, kv)
|
||||||
|
|
||||||
v, k := kv.Value, log.KindSlice
|
v, k := kv.Value, log.KindSlice
|
||||||
t.Run("AsBool", testErrKind(v.AsBool, "AsBool", k))
|
t.Run("AsBool", testErrKind(v.AsBool, "AsBool", k))
|
||||||
@@ -252,13 +252,13 @@ func TestSlice(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMap(t *testing.T) {
|
func TestMap(t *testing.T) {
|
||||||
const key = "key"
|
const key = "mapKey"
|
||||||
val := []log.KeyValue{
|
val := []log.KeyValue{
|
||||||
log.Slice("l", log.IntValue(3), log.StringValue("foo")),
|
log.Slice("l", log.IntValue(3), log.StringValue("foo")),
|
||||||
log.Bytes("b", []byte{3, 5, 7}),
|
log.Bytes("b", []byte{3, 5, 7}),
|
||||||
}
|
}
|
||||||
kv := log.Map(key, val...)
|
kv := log.Map(key, val...)
|
||||||
testKV(t, key, val, kv)
|
testKV(t, key, kv)
|
||||||
|
|
||||||
v, k := kv.Value, log.KindMap
|
v, k := kv.Value, log.KindMap
|
||||||
t.Run("AsBool", testErrKind(v.AsBool, "AsBool", k))
|
t.Run("AsBool", testErrKind(v.AsBool, "AsBool", k))
|
||||||
@@ -339,7 +339,7 @@ func testErrKind[T any](f func() T, msg string, k log.Kind) func(*testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testKV[T any](t *testing.T, key string, val T, kv log.KeyValue) {
|
func testKV(t *testing.T, key string, kv log.KeyValue) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
assert.Equal(t, key, kv.Key, "incorrect key")
|
assert.Equal(t, key, kv.Key, "incorrect key")
|
||||||
|
@@ -31,7 +31,7 @@ func run(steps ...func(*testing.T)) func(*testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setenv(k, v string) func(t *testing.T) {
|
func setenv(k, v string) func(t *testing.T) { //nolint:unparam
|
||||||
return func(t *testing.T) { t.Setenv(k, v) }
|
return func(t *testing.T) { t.Setenv(k, v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -381,7 +381,7 @@ func (bsp *batchSpanProcessor) enqueueBlockOnQueueFull(ctx context.Context, sd R
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bsp *batchSpanProcessor) enqueueDrop(ctx context.Context, sd ReadOnlySpan) bool {
|
func (bsp *batchSpanProcessor) enqueueDrop(_ context.Context, sd ReadOnlySpan) bool {
|
||||||
if !sd.SpanContext().IsSampled() {
|
if !sd.SpanContext().IsSampled() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@@ -340,7 +340,7 @@ func createAndRegisterBatchSP(option testOption, te *testBatchExporter) sdktrace
|
|||||||
return sdktrace.NewBatchSpanProcessor(te, options...)
|
return sdktrace.NewBatchSpanProcessor(te, options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateSpan(t *testing.T, tr trace.Tracer, option testOption) {
|
func generateSpan(_ *testing.T, tr trace.Tracer, option testOption) {
|
||||||
sc := getSpanContext()
|
sc := getSpanContext()
|
||||||
|
|
||||||
for i := 0; i < option.genNumSpans; i++ {
|
for i := 0; i < option.genNumSpans; i++ {
|
||||||
@@ -353,7 +353,7 @@ func generateSpan(t *testing.T, tr trace.Tracer, option testOption) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateSpanParallel(t *testing.T, tr trace.Tracer, option testOption) {
|
func generateSpanParallel(_ *testing.T, tr trace.Tracer, option testOption) {
|
||||||
sc := getSpanContext()
|
sc := getSpanContext()
|
||||||
|
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
|
@@ -321,7 +321,7 @@ func traceBenchmark(b *testing.B, name string, fn func(*testing.B, trace.Tracer)
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func tracer(b *testing.B, name string, sampler sdktrace.Sampler) trace.Tracer {
|
func tracer(_ *testing.B, name string, sampler sdktrace.Sampler) trace.Tracer {
|
||||||
tp := sdktrace.NewTracerProvider(sdktrace.WithSampler(sampler))
|
tp := sdktrace.NewTracerProvider(sdktrace.WithSampler(sampler))
|
||||||
return tp.Tracer(name)
|
return tp.Tracer(name)
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@ import (
|
|||||||
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
sdktrace "go.opentelemetry.io/otel/sdk/trace"
|
||||||
)
|
)
|
||||||
|
|
||||||
func basicTracerProvider(t *testing.T) *sdktrace.TracerProvider {
|
func basicTracerProvider(_ *testing.T) *sdktrace.TracerProvider {
|
||||||
tp := sdktrace.NewTracerProvider(sdktrace.WithSampler(sdktrace.AlwaysSample()))
|
tp := sdktrace.NewTracerProvider(sdktrace.WithSampler(sdktrace.AlwaysSample()))
|
||||||
return tp
|
return tp
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user