From 6c85131a8a934e995dd2db9af9c736e2a0f0be01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20=C5=9Awi=C4=85tek?= Date: Fri, 28 Feb 2025 14:15:57 +0100 Subject: [PATCH] Remove unnecessary loop variable copies (#6997) --- .golangci.yml | 2 +- .../pkg/agent/application/monitoring/processes_cloud_test.go | 2 -- internal/pkg/eql/eql_test.go | 1 - internal/pkg/otel/configtranslate/otelconfig.go | 1 - testing/fleetservertest/server.go | 3 +-- 5 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index f76beb64fcc..50a2b2b7f88 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -46,7 +46,7 @@ linters: - asciicheck # simple linter to check that your code does not contain non-ASCII identifiers - bodyclose # checks whether HTTP response body is closed successfully - durationcheck # check for two durations multiplied together - - exportloopref # checks for pointers to enclosing loop variables + - copyloopvar # checks for unnecessary loop variable copies - goimports # Goimports does everything that gofmt does. Additionally it checks unused imports - gosec # inspects source code for security problems - importas # enforces consistent import aliases diff --git a/internal/pkg/agent/application/monitoring/processes_cloud_test.go b/internal/pkg/agent/application/monitoring/processes_cloud_test.go index f4d6bc904e3..7f83c755ba1 100644 --- a/internal/pkg/agent/application/monitoring/processes_cloud_test.go +++ b/internal/pkg/agent/application/monitoring/processes_cloud_test.go @@ -90,7 +90,6 @@ func TestExpectedCloudProcessID(t *testing.T) { } for _, tc := range testcases { - tc := tc // make a copy to avoid implicit memory aliasing t.Run(tc.name, func(t *testing.T) { assert.Equal(t, tc.id, expectedCloudProcessID(&tc.component)) }) @@ -143,7 +142,6 @@ func TestMatchesCloudProcessID(t *testing.T) { } for _, tc := range testcases { - tc := tc // make a copy to avoid implicit memory aliasing t.Run(tc.name, func(t *testing.T) { assert.Equal(t, tc.matches, matchesCloudProcessID(&tc.component, tc.processID)) }) diff --git a/internal/pkg/eql/eql_test.go b/internal/pkg/eql/eql_test.go index c8425224415..ad37aa9c595 100644 --- a/internal/pkg/eql/eql_test.go +++ b/internal/pkg/eql/eql_test.go @@ -380,7 +380,6 @@ func TestEql(t *testing.T) { } for _, test := range testcases { - test := test var title string if test.err { title = fmt.Sprintf("%s failed parsing", test.expression) diff --git a/internal/pkg/otel/configtranslate/otelconfig.go b/internal/pkg/otel/configtranslate/otelconfig.go index 8df2e683306..ed9398029bd 100644 --- a/internal/pkg/otel/configtranslate/otelconfig.go +++ b/internal/pkg/otel/configtranslate/otelconfig.go @@ -77,7 +77,6 @@ func getSupportedComponents(model *component.Model) []*component.Component { var supportedComponents []*component.Component for _, comp := range model.Components { - comp := comp if IsComponentOtelSupported(&comp) { supportedComponents = append(supportedComponents, &comp) } diff --git a/testing/fleetservertest/server.go b/testing/fleetservertest/server.go index 38dd50337e6..3bbe744a333 100644 --- a/testing/fleetservertest/server.go +++ b/testing/fleetservertest/server.go @@ -110,7 +110,6 @@ func NewRouter(handlers *Handlers) *mux.Router { router := mux.NewRouter().StrictSlash(true) for _, route := range handlers.Routes() { - route := route // needed because it's been captured in the closure router. Methods(route.Method). Path(route.Pattern). @@ -514,7 +513,7 @@ func (s *statusResponseWriter) Header() http.Header { func (s *statusResponseWriter) Write(bs []byte) (int, error) { n, err := s.w.Write(bs) - s.byteCount.Add(uint64(n)) + s.byteCount.Add(uint64(n)) //nolint:gosec// output of Write is guaranteed to be non-negative return n, err }