From 34922749e5d1e1f3ba43d06b3350ab9a3bccf37f Mon Sep 17 00:00:00 2001 From: Kevin Chen Date: Tue, 20 Jun 2023 22:13:38 -0400 Subject: [PATCH] chore: Lint fixes for variable shadowing (#42) --- .golangci.yml | 191 ++++++++++-------------- cmd/saga/start/service/validate_test.go | 2 +- pkg/connect/pgv/convert.go | 2 +- pkg/fxmod/tracing/tracing.go | 2 +- 4 files changed, 85 insertions(+), 112 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 16fc961..8264e51 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -63,6 +63,27 @@ output: path-prefix: "" # all available settings of specific linters linters-settings: + ireturn: + # ireturn does not allow using `allow` and `reject` settings at the same time. + # Both settings are lists of the keywords and regular expressions matched to interface or package names. + # keywords: + # - `empty` for `interface{}` + # - `error` for errors + # - `stdlib` for standard library + # - `anon` for anonymous interfaces + # - `generic` for generic interfaces added in go 1.18 + + # By default, it allows using errors, empty interfaces, anonymous interfaces, + # and interfaces provided by the standard library. + allow: + - anon + - error + - empty + - stdlib + # You can specify idiomatic endings for interface + - (or|er)$ + - go.uber.org/fx.Option + - go.temporal.io/sdk/client.Client varnamelen: # The longest distance, in source lines, that is being considered a "small scope". # Variables used in at most this many lines will be ignored. @@ -111,27 +132,42 @@ linters-settings: - T any - m map[string]int - ok bool - ireturn: - # ireturn does not allow using `allow` and `reject` settings at the same time. - # Both settings are lists of the keywords and regular expressions matched to interface or package names. - # keywords: - # - `empty` for `interface{}` - # - `error` for errors - # - `stdlib` for standard library - # - `anon` for anonymous interfaces - # - `generic` for generic interfaces added in go 1.18 - - # By default, it allows using errors, empty interfaces, anonymous interfaces, - # and interfaces provided by the standard library. - allow: - - anon - - error - - empty - - stdlib - # You can specify idiomatic endings for interface - - (or|er)$ - - go.uber.org/fx.Option - - go.temporal.io/sdk/client.Client + govet: + # Report about shadowed variables. + # Default: false + check-shadowing: true + # Settings per analyzer. + settings: + # Analyzer name, run `go tool vet help` to see all analyzers. + printf: + # Comma-separated list of print function names to check (in addition to default, see `go tool vet help printf`). + # Default: [] + funcs: + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + shadow: + # Whether to be strict about shadowing; can be noisy. + # Default: false + strict: true + unusedresult: + # Comma-separated list of functions whose results must be used + # (in addition to defaults context.WithCancel,context.WithDeadline,context.WithTimeout,context.WithValue, + # errors.New,fmt.Errorf,fmt.Sprint,fmt.Sprintf,sort.Reverse) + # Default [] + funcs: + - pkg.MyFunc + # Comma-separated list of names of methods of type func() string whose results must be used + # (in addition to default Error,String) + # Default [] + stringmethods: + - MyMethod + # Enable all analyzers. + # Default: false + enable-all: true + disable: + - fieldalignment wrapcheck: # An array of strings that specify substrings of signatures to ignore. # If this set, it will override the default set of ignored signatures. @@ -234,6 +270,12 @@ linters-settings: funlen: lines: 80 statements: 40 + +# gci: +# put imports beginning with prefix after 3rd-party packages; +# only support one prefix +# if not set, use goimports.local-prefixes +# local-prefixes: github.com/kevinmichaelchen/temporal-saga-grpc gocognit: # minimal code complexity to report, 30 by default (but we recommend 10-20) min-complexity: 10 @@ -446,94 +488,25 @@ gofumpt: # Intended to point to the repo location of the linter. Optional, just for documentation purposes. # original-url: github.com/golangci/example-linter linters: - disable-all: true - enable: - - asasalint - - asciicheck - - bidichk - - bodyclose - - containedctx - - contextcheck - - cyclop - - decorder -# - depguard - - dogsled - - dupl - - dupword - - durationcheck - - errcheck - - errchkjson - - errname -# - errorlint - - exhaustive -# - exhaustruct - - exportloopref - - forbidigo - - funlen - - gci - - gocheckcompilerdirectives -# - gochecknoglobals - - gochecknoinits - - gocognit - - goconst - - gocritic - - gocyclo - - godot - # - godox - - goerr113 - - gofmt - - gofumpt - - goheader - - goimports - - gomoddirectives - - govet - - goprintffuncname - - gosec - - gosmopolitan - - gosimple - - govet - - importas - - interfacebloat - - ireturn - - ineffassign - - loggercheck - - lll - - maintidx - - misspell - - musttag - - nakedret - - nestif - - noctx - - nolintlint - - nilerr - - nilnil - - nlreturn - - noctx - - nonamedreturns - - nosprintfhostport - - paralleltest - - predeclared - - reassign - - rowserrcheck - - revive - - sqlclosecheck - - staticcheck - - exportloopref - - tagalign - - tagliatelle - - tenv - - thelper - - tparallel - - typecheck - - unconvert - - unparam - - usestdlibvars - - unused - - varnamelen - - wastedassign - - whitespace - - wrapcheck - - wsl + enable-all: true + disable: + - deadcode + - depguard # TEMPORARY + - errorlint # TEMPORARY + - exhaustruct + - exhaustivestruct + - gochecknoglobals + - godox + - golint + - gomnd + - ifshort + - interfacer + - maligned + - nosnakecase + - scopelint + - structcheck + - testpackage + - varcheck issues: # List of regexps of issue texts to exclude, empty list by default. # But independently from this option we use default exclude patterns, diff --git a/cmd/saga/start/service/validate_test.go b/cmd/saga/start/service/validate_test.go index 8b89e17..f5468fe 100644 --- a/cmd/saga/start/service/validate_test.go +++ b/cmd/saga/start/service/validate_test.go @@ -86,7 +86,7 @@ func TestValidate(t *testing.T) { t.Run(testName, func(t *testing.T) { t.Parallel() - err := validate(validator, tc.build()) + err = validate(validator, tc.build()) tc.expect(t, err) }) } diff --git a/pkg/connect/pgv/convert.go b/pkg/connect/pgv/convert.go index ae5b745..c9dbabe 100644 --- a/pkg/connect/pgv/convert.go +++ b/pkg/connect/pgv/convert.go @@ -35,7 +35,7 @@ func Convert(err error) error { pgves, ok := err.(MultiError) if ok { for _, p := range pgves.AllErrors() { - pgve, ok := p.(Error) + pgve, ok = p.(Error) if ok { fieldViolations = append(fieldViolations, &errdetails.BadRequest_FieldViolation{ Field: pgve.Field(), diff --git a/pkg/fxmod/tracing/tracing.go b/pkg/fxmod/tracing/tracing.go index 15ef70b..8dd6e6a 100644 --- a/pkg/fxmod/tracing/tracing.go +++ b/pkg/fxmod/tracing/tracing.go @@ -105,7 +105,7 @@ func NewTracerProvider(lifecycle fx.Lifecycle, opts *ModuleOptions, cfg *Config) log.Println("Shutting down TracerProvider...") - err := tracerProvider.Shutdown(ctx) + err = tracerProvider.Shutdown(ctx) if err != nil { return fmt.Errorf("unable to shut down tracer provider: %w", err) }