From 8921d0b770f69ea96e287ed5f8415cb6712b492a Mon Sep 17 00:00:00 2001 From: ZXYxc <38534716+ZXYxc@users.noreply.github.com> Date: Fri, 16 Aug 2024 12:55:04 +0800 Subject: [PATCH] Enable Lint Rule: redefines-builtin-id (#5791) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Which problem is this PR solving? - Partial Fix for https://github.com/jaegertracing/jaeger/issues/5506 ## Description of the changes - Enabled redefines-builtin-id in revive linter. Replaced function name which redefinition of the built-in function ## 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: ZXYxc --- .golangci.yml | 3 --- cmd/agent/app/configmanager/grpc/manager_test.go | 9 ++------- plugin/sampling/strategyprovider/static/provider.go | 6 +++--- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 7a45e156e89..3f0c56026da 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -211,9 +211,6 @@ linters-settings: # this is idiocy, promotes less readable code. Don't enable. - name: var-declaration disabled: true - # enable after cleanup - - name: redefines-builtin-id - disabled: true # "no nested structs are allowed" - don't enable, doesn't make sense - name: nested-structs disabled: true diff --git a/cmd/agent/app/configmanager/grpc/manager_test.go b/cmd/agent/app/configmanager/grpc/manager_test.go index fa484d25c34..1e422d013f9 100644 --- a/cmd/agent/app/configmanager/grpc/manager_test.go +++ b/cmd/agent/app/configmanager/grpc/manager_test.go @@ -5,7 +5,6 @@ package grpc import ( "context" - "io" "net" "testing" @@ -18,16 +17,12 @@ import ( "github.com/jaegertracing/jaeger/proto-gen/api_v2" ) -func close(t *testing.T, c io.Closer) { - require.NoError(t, c.Close()) -} - func TestSamplingManager_GetSamplingStrategy(t *testing.T) { s, addr := initializeGRPCTestServer(t, func(s *grpc.Server) { api_v2.RegisterSamplingManagerServer(s, &mockSamplingHandler{}) }) conn, err := grpc.NewClient(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials())) - defer close(t, conn) + t.Cleanup(func() { require.NoError(t, conn.Close()) }) require.NoError(t, err) defer s.GracefulStop() manager := NewConfigManager(conn) @@ -38,7 +33,7 @@ func TestSamplingManager_GetSamplingStrategy(t *testing.T) { func TestSamplingManager_GetSamplingStrategy_error(t *testing.T) { conn, err := grpc.NewClient("foo", grpc.WithTransportCredentials(insecure.NewCredentials())) - defer close(t, conn) + t.Cleanup(func() { require.NoError(t, conn.Close()) }) require.NoError(t, err) manager := NewConfigManager(conn) resp, err := manager.GetSamplingStrategy(context.Background(), "any") diff --git a/plugin/sampling/strategyprovider/static/provider.go b/plugin/sampling/strategyprovider/static/provider.go index 9bdb612152e..f02a4031a16 100644 --- a/plugin/sampling/strategyprovider/static/provider.go +++ b/plugin/sampling/strategyprovider/static/provider.go @@ -375,7 +375,7 @@ func deepCopy(s *api_v2.SamplingStrategyResponse) *api_v2.SamplingStrategyRespon enc := gob.NewEncoder(&buf) dec := gob.NewDecoder(&buf) enc.Encode(*s) - var copy api_v2.SamplingStrategyResponse - dec.Decode(©) - return © + var copyValue api_v2.SamplingStrategyResponse + dec.Decode(©Value) + return ©Value }