diff --git a/.golangci.yml b/.golangci.yml index e90f3841f..1787f0487 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -197,12 +197,9 @@ linters: - funlen # revive - gocognit # revive - # - # Disabled until fixed for go 1.22 - # + # Disabled atm - - 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. + - intrange # intrange is a linter to find places where for loops could make use of an integer range. # # Enabled @@ -212,6 +209,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 @@ -490,11 +488,6 @@ issues: path: "cmd/crowdsec-cli/idgen/password.go" text: "deep-exit: .*" - - linters: - - revive - path: "cmd/crowdsec-cli/utils.go" - text: "deep-exit: .*" - - linters: - revive path: "pkg/leakybucket/overflows.go" diff --git a/pkg/acquisition/acquisition.go b/pkg/acquisition/acquisition.go index a737881dd..b2493bbb9 100644 --- a/pkg/acquisition/acquisition.go +++ b/pkg/acquisition/acquisition.go @@ -304,7 +304,7 @@ func LoadAcquisitionFromFile(config *csconfig.CrowdsecServiceCfg, prom *csconfig func GetMetrics(sources []DataSource, aggregated bool) error { var metrics []prometheus.Collector - for i := range len(sources) { + for i := range sources { if aggregated { metrics = sources[i].GetMetrics() } else { @@ -378,7 +378,7 @@ func StartAcquisition(sources []DataSource, output chan types.Event, AcquisTomb return nil } - for i := range len(sources) { + for i := range sources { subsrc := sources[i] // ensure its a copy log.Debugf("starting one source %d/%d ->> %T", i, len(sources), subsrc) diff --git a/pkg/acquisition/modules/docker/utils.go b/pkg/acquisition/modules/docker/utils.go index c724f5811..6a0d49409 100644 --- a/pkg/acquisition/modules/docker/utils.go +++ b/pkg/acquisition/modules/docker/utils.go @@ -22,7 +22,7 @@ func parseKeyToMap(m map[string]interface{}, key string, value string) { return } - for i := range len(parts) { + for i := range parts { if parts[i] == "" { return } diff --git a/pkg/apiclient/decisions_service.go b/pkg/apiclient/decisions_service.go index 388a870f9..98f26cad9 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 51887006a..058e25079 100644 --- a/pkg/apiserver/apic_test.go +++ b/pkg/apiserver/apic_test.go @@ -1091,7 +1091,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 @@ -1114,8 +1113,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 97a3ad33d..b7956bdcc 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.go b/pkg/csplugin/utils_windows.go index 8d4956cee..910020793 100644 --- a/pkg/csplugin/utils_windows.go +++ b/pkg/csplugin/utils_windows.go @@ -116,7 +116,7 @@ func CheckPerms(path string) error { */ aceCount := rs.Field(3).Uint() - for i := uint64(0); i < aceCount; i++ { + for i := range aceCount { ace := &AccessAllowedAce{} ret, _, _ := procGetAce.Call(uintptr(unsafe.Pointer(dacl)), uintptr(i), uintptr(unsafe.Pointer(&ace))) if ret == 0 { diff --git a/pkg/csplugin/utils_windows_test.go b/pkg/csplugin/utils_windows_test.go index 6a76e1215..1eb4dfb90 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 7ed14086a..c82822e64 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/leakybucket/manager_run.go b/pkg/leakybucket/manager_run.go index 053f9be05..2858d8b56 100644 --- a/pkg/leakybucket/manager_run.go +++ b/pkg/leakybucket/manager_run.go @@ -298,7 +298,7 @@ func PourItemToHolders(parsed types.Event, holders []BucketFactory, buckets *Buc BucketPourCache["OK"] = append(BucketPourCache["OK"], evt.(types.Event)) } //find the relevant holders (scenarios) - for idx := range len(holders) { + for idx := range holders { //for idx, holder := range holders { //evaluate bucket's condition diff --git a/pkg/setup/detect_test.go b/pkg/setup/detect_test.go index 6f61b5dac..588e74dab 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)