From bd33dc2f6426f246bf7bf2e5edef4a1ef5d96581 Mon Sep 17 00:00:00 2001 From: FlamingSaint <78465537+FlamingSaint@users.noreply.github.com> Date: Mon, 3 Jun 2024 21:08:16 +0530 Subject: [PATCH] Enable Lint Rules: bare-return & empty-lines (#5512) ## Which problem is this PR solving? - Partial Fix for #5506 ## Description of the changes - Enabled bare-return in revive linter. - Removed naked returns. - Enabled empty-lines in revive linter. ## How was this change tested? - `make lint` `make test` ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [ ] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: FlamingSaint --- .golangci.yml | 6 ------ cmd/collector/app/collector.go | 1 - cmd/query/app/server.go | 1 - cmd/query/app/server_test.go | 2 -- pkg/fswatcher/fswatcher_test.go | 2 +- pkg/gzipfs/gzip.go | 6 +++--- pkg/httpmetrics/metrics.go | 2 +- pkg/kafka/auth/plaintext.go | 6 ++---- plugin/sampling/strategystore/static/strategy_store.go | 1 - plugin/storage/badger/spanstore/reader.go | 1 - plugin/storage/cassandra/spanstore/reader_test.go | 1 - plugin/storage/memory/memory.go | 1 - 12 files changed, 7 insertions(+), 23 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 32237518db1..9370dd45b30 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -213,12 +213,6 @@ linters-settings: # enable after cleanup - name: early-return disabled: true - # enable after cleanup - - name: bare-return - disabled: true - # enable after cleanup - - name: empty-lines - disabled: true # investigate, could be real bugs. But didn't recent Go version changed loop variables semantics? - name: range-val-address disabled: true diff --git a/cmd/collector/app/collector.go b/cmd/collector/app/collector.go index ad6eeca364a..31c9e4532d8 100644 --- a/cmd/collector/app/collector.go +++ b/cmd/collector/app/collector.go @@ -154,7 +154,6 @@ func (c *Collector) Start(options *flags.CollectorOptions) error { return fmt.Errorf("could not start Zipkin receiver: %w", err) } c.zipkinReceiver = zipkinReceiver - } if options.OTLP.Enabled { diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go index 719f3957778..8e1af7662c3 100644 --- a/cmd/query/app/server.go +++ b/cmd/query/app/server.go @@ -205,7 +205,6 @@ func createHTTPServer( return nil, err } server.TLSConfig = tlsCfg - } server.staticHandlerCloser = RegisterStaticHandler(r, logger, queryOpts, querySvc.GetCapabilities()) diff --git a/cmd/query/app/server_test.go b/cmd/query/app/server_test.go index 7a7f9bdf44f..83cc081c026 100644 --- a/cmd/query/app/server_test.go +++ b/cmd/query/app/server_test.go @@ -382,9 +382,7 @@ func TestServerHTTPTLS(t *testing.T) { if conn != nil { clientClose = conn.Close } - } else { - conn, err1 := net.DialTimeout("tcp", "localhost:"+fmt.Sprintf("%d", ports.QueryHTTP), 2*time.Second) clientError = err1 clientClose = nil diff --git a/pkg/fswatcher/fswatcher_test.go b/pkg/fswatcher/fswatcher_test.go index 12fd552cea3..3bae95a2e44 100644 --- a/pkg/fswatcher/fswatcher_test.go +++ b/pkg/fswatcher/fswatcher_test.go @@ -47,7 +47,7 @@ func createTestFiles(t *testing.T) (file1 string, file2 string, file3 string) { err = os.WriteFile(file3, []byte("test data"), 0o600) require.NoError(t, err) - return + return file1, file2, file3 } func TestFSWatcherAddFiles(t *testing.T) { diff --git a/pkg/gzipfs/gzip.go b/pkg/gzipfs/gzip.go index 2f478427548..1a75795cb77 100644 --- a/pkg/gzipfs/gzip.go +++ b/pkg/gzipfs/gzip.go @@ -50,17 +50,17 @@ func (f file) Stat() (fs.FileInfo, error) { }, nil } -func (f *file) Read(buf []byte) (n int, err error) { +func (f *file) Read(buf []byte) (int, error) { if len(buf) > len(f.content)-f.offset { buf = buf[0:len(f.content[f.offset:])] } - n = copy(buf, f.content[f.offset:]) + n := copy(buf, f.content[f.offset:]) if n == len(f.content)-f.offset { return n, io.EOF } f.offset += n - return + return n, nil } func (f file) Close() error { diff --git a/pkg/httpmetrics/metrics.go b/pkg/httpmetrics/metrics.go index 097c4bd1b68..0db8cc5e47d 100644 --- a/pkg/httpmetrics/metrics.go +++ b/pkg/httpmetrics/metrics.go @@ -149,5 +149,5 @@ func (r *requestDurations) buildTimer(metricsFactory metrics.Factory, key record "method": key.method, }, }) - return + return out } diff --git a/pkg/kafka/auth/plaintext.go b/pkg/kafka/auth/plaintext.go index 092047dbbfd..81d940bb130 100644 --- a/pkg/kafka/auth/plaintext.go +++ b/pkg/kafka/auth/plaintext.go @@ -42,9 +42,8 @@ func (x *scramClient) Begin(userName, password, authzID string) (err error) { // Step steps client through the SCRAM exchange. It is // called repeatedly until it errors or `Done` returns true. -func (x *scramClient) Step(challenge string) (response string, err error) { - response, err = x.ClientConversation.Step(challenge) - return +func (x *scramClient) Step(challenge string) (string, error) { + return x.ClientConversation.Step(challenge) } // Done should return true when the SCRAM conversation @@ -84,7 +83,6 @@ func setPlainTextConfiguration(config *PlainTextConfig, saramaConfig *sarama.Con default: return fmt.Errorf("config plaintext.mechanism error: %s, only support 'SCRAM-SHA-256' or 'SCRAM-SHA-512' or 'PLAIN'", config.Mechanism) - } return nil } diff --git a/plugin/sampling/strategystore/static/strategy_store.go b/plugin/sampling/strategystore/static/strategy_store.go index fdf9959a9d8..05debf2d720 100644 --- a/plugin/sampling/strategystore/static/strategy_store.go +++ b/plugin/sampling/strategystore/static/strategy_store.go @@ -278,7 +278,6 @@ func (h *strategyStore) parseStrategies(strategies *strategies) { opS := newStore.serviceStrategies[s.Service].OperationSampling if opS == nil { - // Service does not have its own per-operation rules, so copy (by value) from the default strategy. newOpS := *newStore.defaultStrategy.OperationSampling diff --git a/plugin/storage/badger/spanstore/reader.go b/plugin/storage/badger/spanstore/reader.go index f33dce1136d..484deeaa575 100644 --- a/plugin/storage/badger/spanstore/reader.go +++ b/plugin/storage/badger/spanstore/reader.go @@ -280,7 +280,6 @@ func serviceQueries(query *spanstore.TraceQueryParameters, indexSeeks [][]byte) } else if !tagQueryUsed { // Tag query already reduces the search set with a serviceName indexSearchKey = append(indexSearchKey, serviceNameIndexKey) indexSearchKey = append(indexSearchKey, []byte(query.ServiceName)...) - } if len(indexSearchKey) > 0 { diff --git a/plugin/storage/cassandra/spanstore/reader_test.go b/plugin/storage/cassandra/spanstore/reader_test.go index a305ef97967..816b0db9745 100644 --- a/plugin/storage/cassandra/spanstore/reader_test.go +++ b/plugin/storage/cassandra/spanstore/reader_test.go @@ -402,7 +402,6 @@ func TestSpanReaderFindTraces(t *testing.T) { if testCase.queryDuration { queryParams.DurationMin = time.Minute queryParams.DurationMax = time.Minute * 3 - } res, err := r.reader.FindTraces(context.Background(), queryParams) if testCase.expectedError == "" { diff --git a/plugin/storage/memory/memory.go b/plugin/storage/memory/memory.go index d8da0b6ca2f..cae11e3ae8a 100644 --- a/plugin/storage/memory/memory.go +++ b/plugin/storage/memory/memory.go @@ -187,7 +187,6 @@ func (st *Store) WriteSpan(ctx context.Context, span *model.Span) error { // update the ring with the trace id m.ids[m.index] = &span.TraceID } - } m.traces[span.TraceID].Spans = append(m.traces[span.TraceID].Spans, span)