From 51fca7aab6e9f97d7595a8782533ae61b7e2c2d3 Mon Sep 17 00:00:00 2001 From: Marat Reymers Date: Mon, 11 Nov 2024 14:56:03 +0100 Subject: [PATCH] Update config --- .github/workflows/ci.yml | 2 +- .golangci.yml | 12 ++++++++++-- auth/cache.go | 4 ++-- auth/service_account.go | 2 +- conn/dialer.go | 2 +- conn/resolvers.go | 8 ++++---- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 476c54d..0dbd303 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,7 @@ jobs: go-version: "1.23.3" # update together with dev.dockerfile - uses: golangci/golangci-lint-action@v6 with: - version: "v1.61.0" # update together with dev.dockerfile + version: "v1.62.0" # update together with dev.dockerfile check-tidy: name: go mod tidy diff --git a/.golangci.yml b/.golangci.yml index 349c589..22b4948 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -74,6 +74,11 @@ linters-settings: # Default false ignore-comments: true + gochecksumtype: + # Presence of `default` case in switch statements satisfies exhaustiveness, if all members are not listed. + # Default: true + default-signifies-exhaustive: false + gocognit: # Minimal code complexity to report. # Default: 30 (but we recommend 10-20) @@ -245,6 +250,7 @@ linters: - gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations - goprintffuncname # checks that printf-like functions are named with f at the end - gosec # inspects source code for security problems + - iface # checks the incorrect use of interfaces, helping developers avoid interface pollution - intrange # finds places where for loops could make use of an integer range - lll # reports long lines - loggercheck # checks key value pairs for common logger libraries (kitlog,klog,logr,zap) @@ -266,6 +272,7 @@ linters: - promlinter # checks Prometheus metrics naming via promlint - protogetter # reports direct reads from proto message fields when getters should be used - reassign # checks that package variables are not reassigned + - recvcheck # checks for receiver type consistency - revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint - rowserrcheck # checks whether Err of rows is checked successfully - sloglint # ensure consistent code style when using log/slog @@ -307,7 +314,6 @@ linters: #- dupword # [useless without config] checks for duplicate words in the source code #- err113 # [too strict] checks the errors handling expressions #- errchkjson # [don't see profit + I'm against of omitting errors like in the first example https://github.com/breml/errchkjson] checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted - #- execinquery # [deprecated] checks query string in Query function which reads your Go src files and warning it finds #- exportloopref # [not necessary from Go 1.22] checks for pointers to enclosing loop variables #- forcetypeassert # [replaced by errcheck] finds forced type assertions #- gofmt # [replaced by goimports] checks whether code was gofmt-ed @@ -339,6 +345,7 @@ issues: linters: - bodyclose - dupl + - errcheck - funlen - goconst - gosec @@ -372,12 +379,13 @@ issues: - path: "operations/alphaops" text: "SA1019: .+ is deprecated" - path: "serviceerror" - text: "the type name .+ should conform to the `XxxError` format" + text: "the error type name .+ should conform to the `XxxError` format" - path: "serviceerror" linters: - protogetter # TODO: fix - path: "fieldmask" linters: - nilnil # TODO: fix or ignore + - recvcheck # TODO: fix or ignore - testifylint # TODO: fix or ignore - testpackage # TODO: fix or ignore diff --git a/auth/cache.go b/auth/cache.go index b8aca86..33a5f63 100644 --- a/auth/cache.go +++ b/auth/cache.go @@ -199,7 +199,7 @@ func (c *CachedServiceTokener) requestToken(ctx context.Context, background bool return BearerToken{}, err } - return res.(BearerToken), nil + return res.(BearerToken), nil //nolint:errcheck // ok to panic } type CachedBearerTokener struct { @@ -268,5 +268,5 @@ func (c *CachedBearerTokener) requestToken(ctx context.Context) (BearerToken, er return BearerToken{}, err } - return res.(BearerToken), nil + return res.(BearerToken), nil //nolint:errcheck // ok to panic } diff --git a/auth/service_account.go b/auth/service_account.go index 15092fa..4f0bfc5 100644 --- a/auth/service_account.go +++ b/auth/service_account.go @@ -70,7 +70,7 @@ func (c *CachedServiceAccount) ServiceAccount(ctx context.Context) (ServiceAccou return ServiceAccount{}, err } - return res.(ServiceAccount), nil + return res.(ServiceAccount), nil //nolint:errcheck // ok to panic } type StaticServiceAccount ServiceAccount diff --git a/conn/dialer.go b/conn/dialer.go index 7bca24d..e3ec6c4 100644 --- a/conn/dialer.go +++ b/conn/dialer.go @@ -179,7 +179,7 @@ func (d *dialer) dial(ctx context.Context, address Address) (*grpc.ClientConn, e return nil, err } - return res.(*grpc.ClientConn), nil + return res.(*grpc.ClientConn), nil //nolint:errcheck // ok to panic } func (d *dialer) Close() error { diff --git a/conn/resolvers.go b/conn/resolvers.go index 2f274c7..a584f49 100644 --- a/conn/resolvers.go +++ b/conn/resolvers.go @@ -19,11 +19,11 @@ func ContextWithResolver(ctx context.Context, resolver Resolver) context.Context } func ResolverFromContext(ctx context.Context) Resolver { - value := ctx.Value(resolverContextKey{}) - if value == nil { + res, ok := ctx.Value(resolverContextKey{}).(Resolver) + if !ok { return nil } - return value.(Resolver) + return res } type ContextResolver struct { @@ -185,7 +185,7 @@ func NewCachedResolver(logger *slog.Logger, next Resolver) *CachedResolver { func (r *CachedResolver) Resolve(ctx context.Context, id ServiceID) (Address, error) { if value, ok := r.cache.Load(id); ok { - return value.(Address), nil + return value.(Address), nil //nolint:errcheck // ok to panic } log := r.logger.With(slog.String("service", string(id)))