diff --git a/.golangci.yml b/.golangci.yml index 2b216259770..ac86acd88b7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -196,13 +196,6 @@ linters: - funlen # revive - gocognit # revive - # - # Disabled until fixed for go 1.22 - # - - - copyloopvar # copyloopvar is a linter detects places where loop variables are copied - - intrange # intrange is a linter to find places where for loops could make use of an integer range. - # # Enabled # @@ -211,6 +204,7 @@ linters: # - asciicheck # checks that all code identifiers does not have non-ASCII symbols in the name # - bidichk # Checks for dangerous unicode character sequences # - bodyclose # checks whether HTTP response body is closed successfully + # - copyloopvar # copyloopvar is a linter detects places where loop variables are copied # - decorder # check declaration order and count of types, constants, variables and functions # - depguard # Go linter that checks if package imports are in a list of acceptable packages # - dupword # checks for duplicate words in the source code @@ -234,6 +228,7 @@ linters: # - importas # Enforces consistent import aliases # - ineffassign # Detects when assignments to existing variables are not used # - interfacebloat # A linter that checks the number of methods inside an interface. + # - intrange # intrange is a linter to find places where for loops could make use of an integer range. # - loggercheck # (logrlint): Checks key value pairs for common logger libraries (kitlog,klog,logr,zap). # - logrlint # Check logr arguments. # - maintidx # maintidx measures the maintainability index of each function. diff --git a/pkg/apiclient/decisions_service.go b/pkg/apiclient/decisions_service.go index 388a870f999..98f26cad9ae 100644 --- a/pkg/apiclient/decisions_service.go +++ b/pkg/apiclient/decisions_service.go @@ -144,7 +144,7 @@ func (s *DecisionsService) FetchV3Decisions(ctx context.Context, url string) (*m partialDecisions := make([]*models.Decision, len(decisionsGroup.Decisions)) for idx, decision := range decisionsGroup.Decisions { - decision := decision // fix exportloopref linter message + decision := decision //nolint:copyloopvar // fix exportloopref linter message partialDecisions[idx] = &models.Decision{ Scenario: &scenarioDeleted, Scope: decisionsGroup.Scope, diff --git a/pkg/apiserver/apic_test.go b/pkg/apiserver/apic_test.go index 546a236251f..eb2d9ba8345 100644 --- a/pkg/apiserver/apic_test.go +++ b/pkg/apiserver/apic_test.go @@ -1093,7 +1093,6 @@ func TestAPICPush(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { api := getAPIC(t) api.pushInterval = time.Millisecond @@ -1116,8 +1115,10 @@ func TestAPICPush(t *testing.T) { httpmock.RegisterResponder("POST", "http://api.crowdsec.net/api/signals", httpmock.NewBytesResponder(200, []byte{})) + // capture the alerts to avoid datarace + alerts := tc.alerts go func() { - api.AlertsAddChan <- tc.alerts + api.AlertsAddChan <- alerts time.Sleep(time.Second) api.Shutdown() diff --git a/pkg/csplugin/broker_win_test.go b/pkg/csplugin/broker_win_test.go index 97a3ad33deb..b7956bdcc0a 100644 --- a/pkg/csplugin/broker_win_test.go +++ b/pkg/csplugin/broker_win_test.go @@ -54,7 +54,6 @@ func (s *PluginSuite) TestBrokerInit() { } for _, tc := range tests { - tc := tc s.Run(tc.name, func() { t := s.T() if tc.action != nil { diff --git a/pkg/csplugin/utils_windows_test.go b/pkg/csplugin/utils_windows_test.go index 6a76e1215e5..1eb4dfb9033 100644 --- a/pkg/csplugin/utils_windows_test.go +++ b/pkg/csplugin/utils_windows_test.go @@ -37,7 +37,6 @@ func TestGetPluginNameAndTypeFromPath(t *testing.T) { }, } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { got, got1, err := getPluginTypeAndSubtypeFromPath(tc.path) cstest.RequireErrorContains(t, err, tc.expectedErr) diff --git a/pkg/cwhub/sync.go b/pkg/cwhub/sync.go index 81d41d55971..d2a0abbe7ed 100644 --- a/pkg/cwhub/sync.go +++ b/pkg/cwhub/sync.go @@ -24,7 +24,7 @@ func isYAMLFileName(path string) bool { // returns error if the symlink is dangling or too many symlinks are followed func resolveSymlink(path string) (string, error) { const maxSymlinks = 10 // Prevent infinite loops - for i := 0; i < maxSymlinks; i++ { + for range maxSymlinks { fi, err := os.Lstat(path) if err != nil { return "", err // dangling link diff --git a/pkg/setup/detect_test.go b/pkg/setup/detect_test.go index c744e7d6796..49169a64df1 100644 --- a/pkg/setup/detect_test.go +++ b/pkg/setup/detect_test.go @@ -184,7 +184,6 @@ func TestNormalizeVersion(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.version, func(t *testing.T) { t.Parallel() actual := setup.NormalizeVersion(tc.version)