From faa5b482f655eca37910b15f8ddc8da5eb522d10 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Fri, 4 Apr 2025 14:52:45 +0200 Subject: [PATCH] lint/refactor: defer, reflectvaluecompare, stylecheck (#3544) * lint: enable reflectvaluecompare * lint: remove exception * lint: stylecheck ST016 - methods on the same type should have the same receiver name * lint: enable revive[time-equal] --- .golangci.yml | 9 --------- cmd/crowdsec/serve.go | 2 +- pkg/apiclient/client.go | 8 ++++---- pkg/parser/runtime.go | 5 ++--- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index a169984d8..cd5f4aef7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -183,7 +183,6 @@ linters: govet: disable: - - reflectvaluecompare - fieldalignment enable-all: true @@ -269,8 +268,6 @@ linters: disabled: true - name: redundant-import-alias disabled: true - - name: time-equal - disabled: true - name: var-naming disabled: true - name: unchecked-type-assertion @@ -304,7 +301,6 @@ linters: - -ST1003 - -ST1005 - -ST1012 - - -ST1016 - -ST1022 - -QF1003 - -QF1008 @@ -379,11 +375,6 @@ linters: path: pkg/acquisition/modules/victorialogs/internal/vlclient/vl_client.go text: 'confusing-naming: Method ''QueryRange'' differs only by capitalization to method ''queryRange'' in the same source file' - - linters: - - revive - path: pkg/hubtest/hubtest_item.go - text: 'cyclomatic: .*RunWithLogFile' - # tolerate complex functions in tests for now - linters: - maintidx diff --git a/cmd/crowdsec/serve.go b/cmd/crowdsec/serve.go index a9e496fe3..642ac46b8 100644 --- a/cmd/crowdsec/serve.go +++ b/cmd/crowdsec/serve.go @@ -23,7 +23,7 @@ import ( "github.com/crowdsecurity/crowdsec/pkg/types" ) -//nolint:deadcode,unused // debugHandler is kept as a dev convenience: it shuts down and serialize internal state +//nolint:unused // debugHandler is kept as a dev convenience: it shuts down and serialize internal state func debugHandler(sig os.Signal, cConfig *csconfig.Config) error { var ( tmpFile string diff --git a/pkg/apiclient/client.go b/pkg/apiclient/client.go index 9ea683c41..9192bf095 100644 --- a/pkg/apiclient/client.go +++ b/pkg/apiclient/client.go @@ -48,12 +48,12 @@ type ApiClient struct { UsageMetrics *UsageMetricsService } -func (a *ApiClient) GetClient() *http.Client { - return a.client +func (c *ApiClient) GetClient() *http.Client { + return c.client } -func (a *ApiClient) IsEnrolled() bool { - jwtTransport := a.client.Transport.(*JWTTransport) +func (c *ApiClient) IsEnrolled() bool { + jwtTransport := c.client.Transport.(*JWTTransport) tokenStr := jwtTransport.Token token, _ := jwt.Parse(tokenStr, nil) diff --git a/pkg/parser/runtime.go b/pkg/parser/runtime.go index 7af82a715..831e478af 100644 --- a/pkg/parser/runtime.go +++ b/pkg/parser/runtime.go @@ -42,9 +42,8 @@ func SetTargetByName(target string, value string, evt *types.Event) bool { }() iter := reflect.ValueOf(evt).Elem() - if (iter == reflect.Value{}) || iter.IsZero() { + if !iter.IsValid() || iter.IsZero() { log.Tracef("event is nil") - //event is nil return false } @@ -56,7 +55,7 @@ func SetTargetByName(target string, value string, evt *types.Event) bool { case reflect.Map: tmp := iter.MapIndex(reflect.ValueOf(f)) /*if we're in a map and the field doesn't exist, the user wants to add it :) */ - if (tmp == reflect.Value{}) || tmp.IsZero() { + if !tmp.IsValid() || tmp.IsZero() { log.Debugf("map entry is zero in '%s'", target) }