From db99b4306816415fb8fe847da1209a18f577b4ed Mon Sep 17 00:00:00 2001 From: Wang Bing Date: Sat, 7 May 2022 03:55:17 +0800 Subject: [PATCH] Use revive instead of golint (#1685) Signed-off-by: pigletfly Co-authored-by: Yaron Schneider --- .github/workflows/components-contrib.yml | 2 +- .golangci.yml | 37 ++++++++++++++++--- bindings/azure/cosmosdb/cosmosdb.go | 2 +- .../servicebusqueues/servicebusqueues_test.go | 2 +- bindings/cron/cron.go | 2 +- bindings/http/http.go | 2 +- bindings/mysql/mysql_test.go | 2 +- bindings/rabbitmq/rabbitmq_test.go | 2 +- bindings/redis/redis_test.go | 2 +- bindings/zeebe/command/command_test.go | 1 + bindings/zeebe/jobworker/jobworker_test.go | 1 + nameresolution/consul/configuration.go | 13 ++++--- pubsub/azure/servicebus/message.go | 1 - secretstores/secret_store.go | 6 +-- state/couchbase/couchbase_test.go | 2 +- state/postgresql/postgresdbaccess.go | 2 +- .../postgresql/postgresql_integration_test.go | 2 +- state/redis/redis.go | 1 - 18 files changed, 54 insertions(+), 28 deletions(-) diff --git a/.github/workflows/components-contrib.yml b/.github/workflows/components-contrib.yml index 620ea2262..786115dae 100644 --- a/.github/workflows/components-contrib.yml +++ b/.github/workflows/components-contrib.yml @@ -33,7 +33,7 @@ jobs: GOOS: ${{ matrix.target_os }} GOARCH: ${{ matrix.target_arch }} GOPROXY: https://proxy.golang.org - GOLANGCI_LINT_VER: v1.31 + GOLANGCI_LINT_VER: v1.45.2 strategy: matrix: os: [ubuntu-latest, windows-latest, macOS-latest] diff --git a/.golangci.yml b/.golangci.yml index 3f3fbfd12..bc65b51cf 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -28,7 +28,7 @@ run: # won't be reported. Default value is empty list, but there is # no need to include all autogenerated files, we confidently recognize # autogenerated files. If it's not please let us know. - skip-files: + # skip-files: # - ".*\\.my\\.go$" # - lib/bad.go @@ -62,7 +62,7 @@ linters-settings: # path to a file containing a list of functions to exclude from checking # see https://github.com/kisielk/errcheck#excluding-functions for details - exclude: + # exclude: funlen: lines: 60 @@ -88,9 +88,9 @@ linters-settings: disable: - shadow disable-all: false - golint: + revive: # minimal confidence for issues, default is 0.8 - min-confidence: 0.8 + confidence: 0.8 gofmt: # simplify code: gofmt with `-s` option, true by default simplify: true @@ -127,7 +127,7 @@ linters-settings: # Correct spellings using locale preferences for US or UK. # Default is to use a neutral variety of English. # Setting locale to US will correct the British spelling of 'colour' to 'color'. - locale: default + # locale: Default ignore-words: - someword lll: @@ -165,7 +165,7 @@ linters-settings: # See https://go-critic.github.io/overview#checks-overview # To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run` # By default list of stable checks is used. - enabled-checks: + # enabled-checks: # Which checks should be disabled; can't be combined with 'enabled-checks'; default is empty disabled-checks: @@ -246,3 +246,28 @@ linters: - exhaustive - noctx - gci + - golint + - tparallel + - paralleltest + - wrapcheck + - tagliatelle + - ireturn + - exhaustivestruct + - errchkjson + - contextcheck + - gomoddirectives + - godot + - cyclop + - varnamelen + - gosec + - errorlint + - forcetypeassert + - ifshort + - maintidx + - nilnil + - predeclared + - tenv + - thelper + - wastedassign + - containedctx + - gosimple diff --git a/bindings/azure/cosmosdb/cosmosdb.go b/bindings/azure/cosmosdb/cosmosdb.go index f3e532b37..c82103ddd 100644 --- a/bindings/azure/cosmosdb/cosmosdb.go +++ b/bindings/azure/cosmosdb/cosmosdb.go @@ -21,7 +21,7 @@ import ( "time" "github.com/a8m/documentdb" - "github.com/cenkalti/backoff/v4" + backoff "github.com/cenkalti/backoff/v4" "github.com/dapr/components-contrib/authentication/azure" "github.com/dapr/components-contrib/bindings" diff --git a/bindings/azure/servicebusqueues/servicebusqueues_test.go b/bindings/azure/servicebusqueues/servicebusqueues_test.go index ee64ede67..7b248ef72 100644 --- a/bindings/azure/servicebusqueues/servicebusqueues_test.go +++ b/bindings/azure/servicebusqueues/servicebusqueues_test.go @@ -25,7 +25,7 @@ import ( ) func TestParseMetadata(t *testing.T) { - var oneSecondDuration time.Duration = time.Second + oneSecondDuration := time.Second testCases := []struct { name string diff --git a/bindings/cron/cron.go b/bindings/cron/cron.go index 0b26878c8..f62e55ac8 100644 --- a/bindings/cron/cron.go +++ b/bindings/cron/cron.go @@ -19,7 +19,7 @@ import ( "time" "github.com/pkg/errors" - "github.com/robfig/cron/v3" + cron "github.com/robfig/cron/v3" "github.com/dapr/components-contrib/bindings" "github.com/dapr/kit/logger" diff --git a/bindings/http/http.go b/bindings/http/http.go index 8d598f2e1..7e3da4ee3 100644 --- a/bindings/http/http.go +++ b/bindings/http/http.go @@ -33,7 +33,7 @@ import ( ) // HTTPSource is a binding for an http url endpoint invocation -// nolint:golint +//revive:disable-next-line type HTTPSource struct { metadata httpMetadata client *http.Client diff --git a/bindings/mysql/mysql_test.go b/bindings/mysql/mysql_test.go index 11870e6c0..b4d12e564 100644 --- a/bindings/mysql/mysql_test.go +++ b/bindings/mysql/mysql_test.go @@ -20,7 +20,7 @@ import ( "testing" "time" - "github.com/DATA-DOG/go-sqlmock" + sqlmock "github.com/DATA-DOG/go-sqlmock" "github.com/stretchr/testify/assert" "github.com/dapr/components-contrib/bindings" diff --git a/bindings/rabbitmq/rabbitmq_test.go b/bindings/rabbitmq/rabbitmq_test.go index 3433d3b9a..0e2a58d24 100644 --- a/bindings/rabbitmq/rabbitmq_test.go +++ b/bindings/rabbitmq/rabbitmq_test.go @@ -27,7 +27,7 @@ import ( func TestParseMetadata(t *testing.T) { const queueName = "test-queue" const host = "test-host" - var oneSecondTTL time.Duration = time.Second + oneSecondTTL := time.Second testCases := []struct { name string diff --git a/bindings/redis/redis_test.go b/bindings/redis/redis_test.go index 7cd6a892c..f57d81993 100644 --- a/bindings/redis/redis_test.go +++ b/bindings/redis/redis_test.go @@ -17,7 +17,7 @@ import ( "context" "testing" - "github.com/alicebob/miniredis/v2" + miniredis "github.com/alicebob/miniredis/v2" "github.com/go-redis/redis/v8" "github.com/stretchr/testify/assert" diff --git a/bindings/zeebe/command/command_test.go b/bindings/zeebe/command/command_test.go index 25239f521..07721d3c1 100644 --- a/bindings/zeebe/command/command_test.go +++ b/bindings/zeebe/command/command_test.go @@ -38,6 +38,7 @@ type mockClient struct { } func (mcf mockClientFactory) Get(metadata bindings.Metadata) (zbc.Client, error) { + //nolint:staticcheck mcf.metadata = metadata if mcf.error != nil { diff --git a/bindings/zeebe/jobworker/jobworker_test.go b/bindings/zeebe/jobworker/jobworker_test.go index e9e205ffd..a691d458d 100644 --- a/bindings/zeebe/jobworker/jobworker_test.go +++ b/bindings/zeebe/jobworker/jobworker_test.go @@ -36,6 +36,7 @@ type mockClient struct { } func (mcf mockClientFactory) Get(metadata bindings.Metadata) (zbc.Client, error) { + //nolint:staticcheck mcf.metadata = metadata if mcf.error != nil { diff --git a/nameresolution/consul/configuration.go b/nameresolution/consul/configuration.go index f08f674b8..99092f16e 100644 --- a/nameresolution/consul/configuration.go +++ b/nameresolution/consul/configuration.go @@ -327,7 +327,7 @@ func mapAdvancedRegistration(config *AgentServiceRegistration) *consul.AgentServ return mapped } -//nolint:golint,stylecheck +//nolint:stylecheck type HttpBasicAuth struct { Username string Password string @@ -337,11 +337,12 @@ type Config struct { Address string Scheme string Datacenter string - HttpAuth *HttpBasicAuth //nolint:golint,stylecheck - WaitTime time.Duration - Token string - TokenFile string - TLSConfig TLSConfig + //nolint:stylecheck + HttpAuth *HttpBasicAuth + WaitTime time.Duration + Token string + TokenFile string + TLSConfig TLSConfig } type TLSConfig struct { diff --git a/pubsub/azure/servicebus/message.go b/pubsub/azure/servicebus/message.go index f6bbab721..1f2dba91f 100644 --- a/pubsub/azure/servicebus/message.go +++ b/pubsub/azure/servicebus/message.go @@ -114,7 +114,6 @@ func NewPubsubMessageFromASBMessage(asbMsg *azservicebus.Message, topic string) // Always set delivery count. addToMetadata(pubsubMsg, DeliveryCountMetadataKey, strconv.FormatInt(int64(asbMsg.DeliveryCount), 10)) - //nolint:golint,nestif if asbMsg.SystemProperties != nil { systemProps := asbMsg.SystemProperties if systemProps.EnqueuedTime != nil { diff --git a/secretstores/secret_store.go b/secretstores/secret_store.go index 7a87985aa..a72131aca 100644 --- a/secretstores/secret_store.go +++ b/secretstores/secret_store.go @@ -15,10 +15,10 @@ package secretstores // SecretStore is the interface for a component that handles secrets management. type SecretStore interface { - // Init authenticates with the actual secret store and performs other init operation + // Init authenticates with the actual secret store and performs other init operation. Init(metadata Metadata) error - // GetSecret retrieves a secret using a key and returns a map of decrypted string/string values + // GetSecret retrieves a secret using a key and returns a map of decrypted string/string values. GetSecret(req GetSecretRequest) (GetSecretResponse, error) - // BulkGetSecret retrieves all secrets in the store and returns a map of decrypted string/string values + // BulkGetSecret retrieves all secrets in the store and returns a map of decrypted string/string values. BulkGetSecret(req BulkGetSecretRequest) (BulkGetSecretResponse, error) } diff --git a/state/couchbase/couchbase_test.go b/state/couchbase/couchbase_test.go index b5e14520c..c27b754f9 100644 --- a/state/couchbase/couchbase_test.go +++ b/state/couchbase/couchbase_test.go @@ -117,7 +117,7 @@ func TestETagToCas(t *testing.T) { t.Run("with valid string", func(t *testing.T) { casStr := "1572938024378368000" ver := uint64(1572938024378368000) - var expectedCas gocb.Cas = gocb.Cas(ver) + expectedCas := gocb.Cas(ver) cas, err := eTagToCas(casStr) assert.Equal(t, nil, err) assert.Equal(t, expectedCas, cas) diff --git a/state/postgresql/postgresdbaccess.go b/state/postgresql/postgresdbaccess.go index 8b079e858..82cd70c84 100644 --- a/state/postgresql/postgresdbaccess.go +++ b/state/postgresql/postgresdbaccess.go @@ -411,7 +411,7 @@ func (p *postgresDBAccess) ensureStateTable(stateTableName string) error { } func tableExists(db *sql.DB, tableName string) (bool, error) { - var exists bool = false + exists := false err := db.QueryRow("SELECT EXISTS (SELECT FROM pg_tables where tablename = $1)", tableName).Scan(&exists) return exists, err diff --git a/state/postgresql/postgresql_integration_test.go b/state/postgresql/postgresql_integration_test.go index f712f881b..c2784658c 100644 --- a/state/postgresql/postgresql_integration_test.go +++ b/state/postgresql/postgresql_integration_test.go @@ -556,7 +556,7 @@ func storeItemExists(t *testing.T, key string) bool { assert.Nil(t, err) defer db.Close() - var exists bool = false + exists := false statement := fmt.Sprintf(`SELECT EXISTS (SELECT FROM %s WHERE key = $1)`, tableName) err = db.QueryRow(statement, key).Scan(&exists) assert.Nil(t, err) diff --git a/state/redis/redis.go b/state/redis/redis.go index 8a776fa66..405dcdffd 100644 --- a/state/redis/redis.go +++ b/state/redis/redis.go @@ -403,7 +403,6 @@ func (r *StateStore) Multi(request *state.TransactionalStateRequest) error { pipe := r.client.TxPipeline() for _, o := range request.Operations { - //nolint:golint,nestif if o.Operation == state.Upsert { req := o.Request.(state.SetRequest) ver, err := r.parseETag(&req)