diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 515750af6..5e0ac1d0a 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: golangci-lint - uses: golangci/golangci-lint-action@v6.5.2 + uses: golangci/golangci-lint-action@v7.0.0 with: - verify: false # disable verifying the configuration since golangci is currently introducing breaking changes in the configuration + verify: true diff --git a/.golangci.yml b/.golangci.yml index 285aca6b3..872454ff7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,3 +1,34 @@ +version: "2" run: timeout: 5m tests: false +linters: + settings: + staticcheck: + checks: + - all + # Incorrect or missing package comment. + # https://staticcheck.dev/docs/checks/#ST1000 + - -ST1000 + # Omit embedded fields from selector expression. + # https://staticcheck.dev/docs/checks/#QF1008 + - -QF1008 + - -ST1003 + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/command.go b/command.go index 364706e3e..3253af6cc 100644 --- a/command.go +++ b/command.go @@ -1412,7 +1412,8 @@ func (cmd *MapStringSliceInterfaceCmd) readReply(rd *proto.Reader) (err error) { cmd.val = make(map[string][]interface{}) - if readType == proto.RespMap { + switch readType { + case proto.RespMap: n, err := rd.ReadMapLen() if err != nil { return err @@ -1435,7 +1436,7 @@ func (cmd *MapStringSliceInterfaceCmd) readReply(rd *proto.Reader) (err error) { cmd.val[k][j] = value } } - } else if readType == proto.RespArray { + case proto.RespArray: // RESP2 response n, err := rd.ReadArrayLen() if err != nil { diff --git a/extra/rediscensus/go.mod b/extra/rediscensus/go.mod index 7033e805f..b39f7dd4c 100644 --- a/extra/rediscensus/go.mod +++ b/extra/rediscensus/go.mod @@ -19,6 +19,6 @@ require ( ) retract ( - v9.5.3 // This version was accidentally released. v9.7.2 // This version was accidentally released. + v9.5.3 // This version was accidentally released. ) diff --git a/extra/rediscmd/go.mod b/extra/rediscmd/go.mod index c1cff3e90..93cc423db 100644 --- a/extra/rediscmd/go.mod +++ b/extra/rediscmd/go.mod @@ -16,6 +16,6 @@ require ( ) retract ( - v9.5.3 // This version was accidentally released. v9.7.2 // This version was accidentally released. + v9.5.3 // This version was accidentally released. ) diff --git a/extra/redisotel/go.mod b/extra/redisotel/go.mod index e5b442e61..c5b29dffa 100644 --- a/extra/redisotel/go.mod +++ b/extra/redisotel/go.mod @@ -24,6 +24,6 @@ require ( ) retract ( - v9.5.3 // This version was accidentally released. v9.7.2 // This version was accidentally released. + v9.5.3 // This version was accidentally released. ) diff --git a/extra/redisprometheus/go.mod b/extra/redisprometheus/go.mod index 8bff00086..c934767e0 100644 --- a/extra/redisprometheus/go.mod +++ b/extra/redisprometheus/go.mod @@ -23,6 +23,6 @@ require ( ) retract ( - v9.5.3 // This version was accidentally released. v9.7.2 // This version was accidentally released. + v9.5.3 // This version was accidentally released. ) diff --git a/options.go b/options.go index 0ebeec342..3ffcd07ed 100644 --- a/options.go +++ b/options.go @@ -214,9 +214,10 @@ func (opt *Options) init() { opt.ConnMaxIdleTime = 30 * time.Minute } - if opt.MaxRetries == -1 { + switch opt.MaxRetries { + case -1: opt.MaxRetries = 0 - } else if opt.MaxRetries == 0 { + case 0: opt.MaxRetries = 3 } switch opt.MinRetryBackoff { diff --git a/osscluster.go b/osscluster.go index 20180464e..3b46cbe35 100644 --- a/osscluster.go +++ b/osscluster.go @@ -111,9 +111,10 @@ type ClusterOptions struct { } func (opt *ClusterOptions) init() { - if opt.MaxRedirects == -1 { + switch opt.MaxRedirects { + case -1: opt.MaxRedirects = 0 - } else if opt.MaxRedirects == 0 { + case 0: opt.MaxRedirects = 3 } diff --git a/ring.go b/ring.go index 0ff3f75b1..8f2dd3c40 100644 --- a/ring.go +++ b/ring.go @@ -128,9 +128,10 @@ func (opt *RingOptions) init() { opt.NewConsistentHash = newRendezvous } - if opt.MaxRetries == -1 { + switch opt.MaxRetries { + case -1: opt.MaxRetries = 0 - } else if opt.MaxRetries == 0 { + case 0: opt.MaxRetries = 3 } switch opt.MinRetryBackoff { diff --git a/sentinel_test.go b/sentinel_test.go index cde7f956d..2d481d5fc 100644 --- a/sentinel_test.go +++ b/sentinel_test.go @@ -41,7 +41,7 @@ var _ = Describe("Sentinel resolution", func() { client := redis.NewFailoverClient(&redis.FailoverOptions{ MasterName: sentinelName, SentinelAddrs: sentinelAddrs, - MaxRetries: -1, + MaxRetries: -1, }) err := client.Ping(shortCtx).Err() diff --git a/universal.go b/universal.go index 3d91dd493..46d5640da 100644 --- a/universal.go +++ b/universal.go @@ -259,13 +259,13 @@ var ( // NewUniversalClient returns a new multi client. The type of the returned client depends // on the following conditions: // -// 1. If the MasterName option is specified with RouteByLatency, RouteRandomly or IsClusterMode, -// a FailoverClusterClient is returned. -// 2. If the MasterName option is specified without RouteByLatency, RouteRandomly or IsClusterMode, -// a sentinel-backed FailoverClient is returned. -// 3. If the number of Addrs is two or more, or IsClusterMode option is specified, -// a ClusterClient is returned. -// 4. Otherwise, a single-node Client is returned. +// 1. If the MasterName option is specified with RouteByLatency, RouteRandomly or IsClusterMode, +// a FailoverClusterClient is returned. +// 2. If the MasterName option is specified without RouteByLatency, RouteRandomly or IsClusterMode, +// a sentinel-backed FailoverClient is returned. +// 3. If the number of Addrs is two or more, or IsClusterMode option is specified, +// a ClusterClient is returned. +// 4. Otherwise, a single-node Client is returned. func NewUniversalClient(opts *UniversalOptions) UniversalClient { switch { case opts.MasterName != "" && (opts.RouteByLatency || opts.RouteRandomly || opts.IsClusterMode):