Skip to content

Commit

Permalink
Add unparam linter (open-telemetry#5803)
Browse files Browse the repository at this point in the history
This is the contrib counterpart of
open-telemetry/opentelemetry-go#5531, adding the
unparam linter.
  • Loading branch information
dmathieu committed Jun 26, 2024
1 parent 114000d commit 06c46b8
Show file tree
Hide file tree
Showing 12 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ linters:
- staticcheck
- typecheck
- unconvert
- unparam
- unused

issues:
Expand Down
2 changes: 1 addition & 1 deletion detectors/gcp/cloud-function.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (f *cloudFunction) Detect(ctx context.Context) (*resource.Resource, error)
if err != nil {
return nil, err
}
region, err := f.cloudRun.cloudRegion(ctx)
region, err := f.cloudRun.cloudRegion()
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions detectors/gcp/cloud-run.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func NewCloudRun() *CloudRun {
}
}

func (c *CloudRun) cloudRegion(ctx context.Context) (string, error) {
func (c *CloudRun) cloudRegion() (string, error) {
region, err := c.mc.Get("instance/region")
if err != nil {
return "", err
Expand Down Expand Up @@ -84,7 +84,7 @@ func (c *CloudRun) Detect(ctx context.Context) (*resource.Resource, error) {
attributes = append(attributes, semconv.CloudAccountID(projectID))
}

if region, err := c.cloudRegion(ctx); hasProblem(err) {
if region, err := c.cloudRegion(); hasProblem(err) {
errInfo = append(errInfo, err.Error())
} else if region != "" {
attributes = append(attributes, semconv.CloudRegion(region))
Expand Down
4 changes: 2 additions & 2 deletions instrgen/lib/context_propagation.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (pass *ContextPropagationPass) Execute(
// when callexpr is inside var decl
// instead of functiondecl
currentFun := FuncDescriptor{}
emitEmptyContext := func(callExpr *ast.CallExpr, fun FuncDescriptor, ctxArg *ast.Ident) {
emitEmptyContext := func(callExpr *ast.CallExpr, ctxArg *ast.Ident) {
addImports = true
if currentFun != (FuncDescriptor{}) {
visited := map[FuncDescriptor]bool{}
Expand Down Expand Up @@ -96,7 +96,7 @@ func (pass *ContextPropagationPass) Execute(
visited := map[FuncDescriptor]bool{}
if isPath(analysis.Callgraph, fun, analysis.RootFunctions[0], visited) {
fmt.Println("\t\t\tContextPropagation FuncCall:", funId, pkg.TypesInfo.Uses[ident].Type().String())
emitEmptyContext(callExpr, fun, ctxArg)
emitEmptyContext(callExpr, ctxArg)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestNotFoundIsNotError(t *testing.T) {

func assertSpan(t *testing.T, span sdktrace.ReadOnlySpan, name string, kind trace.SpanKind, attrs ...attribute.KeyValue) {
assert.Equal(t, name, span.Name())
assert.Equal(t, trace.SpanKindServer, span.SpanKind())
assert.Equal(t, kind, span.SpanKind())

got := make(map[attribute.Key]attribute.Value, len(span.Attributes()))
for _, a := range span.Attributes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ func checkUnaryServerSpans(t *testing.T, spans []trace.ReadOnlySpan) {
}, largeSpan.Attributes())
}

func assertEvents(t *testing.T, expected, actual []trace.Event) bool {
func assertEvents(t *testing.T, expected, actual []trace.Event) bool { //nolint:unparam
if !assert.Len(t, actual, len(expected)) {
return false
}
Expand Down Expand Up @@ -694,7 +694,7 @@ func checkUnaryServerRecords(t *testing.T, reader metric.Reader) {
metricdatatest.AssertEqual(t, want, rm.ScopeMetrics[0], metricdatatest.IgnoreTimestamp(), metricdatatest.IgnoreValue())
}

func findAttribute(kvs []attribute.KeyValue, key attribute.Key) (attribute.KeyValue, bool) {
func findAttribute(kvs []attribute.KeyValue, key attribute.Key) (attribute.KeyValue, bool) { //nolint:unparam
for _, kv := range kvs {
if kv.Key == key {
return kv, true
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/runtime/internal/x/x_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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) }
}

Expand Down
2 changes: 1 addition & 1 deletion samplers/aws/xray/fallback_sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (fs *FallbackSampler) Description() string {
}

// take consumes quota from reservoir, if any remains, then returns true. False otherwise.
func (fs *FallbackSampler) take(now time.Time, itemCost float64) bool {
func (fs *FallbackSampler) take(now time.Time, itemCost float64) bool { //nolint:unparam
fs.mu.Lock()
defer fs.mu.Unlock()

Expand Down
2 changes: 1 addition & 1 deletion samplers/aws/xray/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ type xrayClient struct {
}

// newClient returns an HTTP client with proxy endpoint.
func newClient(endpoint url.URL) (client *xrayClient, err error) {
func newClient(endpoint url.URL) (client *xrayClient, err error) { //nolint:unparam
// Construct resolved URLs for getSamplingRules and getSamplingTargets API calls.
endpoint.Path = "/GetSamplingRules"
samplingRulesURL := endpoint
Expand Down
2 changes: 1 addition & 1 deletion samplers/aws/xray/internal/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (m *Manifest) updateReservoir(t *samplingTargetDocument) (err error) {

// snapshots takes a snapshot of sampling statistics from all rules, resetting
// statistics counters in the process.
func (m *Manifest) snapshots() ([]*samplingStatisticsDocument, error) {
func (m *Manifest) snapshots() ([]*samplingStatisticsDocument, error) { //nolint:unparam
statistics := make([]*samplingStatisticsDocument, 0, len(m.Rules))

// Generate sampling statistics for user-defined rules.
Expand Down
2 changes: 1 addition & 1 deletion samplers/aws/xray/internal/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/stretchr/testify/assert"
)

func createSamplingTargetDocument(name string, interval int64, rate, quota, ttl float64) *samplingTargetDocument {
func createSamplingTargetDocument(name string, interval int64, rate, quota, ttl float64) *samplingTargetDocument { //nolint:unparam
return &samplingTargetDocument{
FixedRate: &rate,
Interval: &interval,
Expand Down
2 changes: 1 addition & 1 deletion samplers/aws/xray/internal/reservoir.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r *reservoir) expired(now time.Time) bool {
}

// take consumes quota from reservoir, if any remains, then returns true. False otherwise.
func (r *reservoir) take(now time.Time, borrowed bool, itemCost float64) bool { // nolint: revive // borrowed is not a control flag.
func (r *reservoir) take(now time.Time, borrowed bool, itemCost float64) bool { // nolint:unparam,revive // borrowed is not a control flag.
r.mu.Lock()
defer r.mu.Unlock()

Expand Down

0 comments on commit 06c46b8

Please sign in to comment.