Skip to content

Commit

Permalink
Remove unnecessary loop variable copies (elastic#6997)
Browse files Browse the repository at this point in the history
  • Loading branch information
swiatekm authored Feb 28, 2025
1 parent 68aa6d1 commit 6c85131
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down Expand Up @@ -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))
})
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/eql/eql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/otel/configtranslate/otelconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions testing/fleetservertest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 6c85131

Please sign in to comment.