From d8ef1c082f6c0b76294a7a64689d02eb6f6d4875 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 30 Nov 2023 21:08:44 +0100 Subject: [PATCH 01/30] Adding asciicheck as a linter Checks that all code identifiers does not have non-ASCII symbols in the name. Signed-off-by: Yolan Romailler --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 5f018970eb7..23525a067fa 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,6 +19,7 @@ linters-settings: linters: disable-all: true enable: + - asciicheck - bodyclose - errcheck - gci @@ -34,7 +35,6 @@ linters: - unconvert - unused # these are implicitly disabled: - # - asciicheck # - depguard # - dogsled # - dupl From 722fa94975e35cc4471b4857b97c068842826bf6 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 30 Nov 2023 21:11:56 +0100 Subject: [PATCH 02/30] Adding bidichk as a linter Checks for dangerous unicode character sequences. Signed-off-by: Yolan Romailler --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index 23525a067fa..c0bdfceb869 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,6 +20,7 @@ linters: disable-all: true enable: - asciicheck + - bidichk - bodyclose - errcheck - gci From f2e30190c17520586e74a54f5e6c82e5783fddf5 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 30 Nov 2023 21:24:20 +0100 Subject: [PATCH 03/30] Adding asasalint as a linter Check for pass []any as any in variadic func(...any). Signed-off-by: Yolan Romailler --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index c0bdfceb869..48ce6a0c31b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,6 +19,7 @@ linters-settings: linters: disable-all: true enable: + - asasalint - asciicheck - bidichk - bodyclose From cf20b78f70ff73d2cac12091f5a810cff9e11123 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 30 Nov 2023 21:25:41 +0100 Subject: [PATCH 04/30] Adding doglsed as a linter Checks assignments with too many blank identifiers (e.g. x, , , _, := f()). Signed-off-by: Yolan Romailler --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 48ce6a0c31b..bef04abe59d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -23,6 +23,7 @@ linters: - asciicheck - bidichk - bodyclose + - dogsled - errcheck - gci - gofumpt @@ -38,7 +39,6 @@ linters: - unused # these are implicitly disabled: # - depguard - # - dogsled # - dupl # - exhaustive # - exportloopref From 79f24c053928c47bc34b25d0ce6fb6f075ef21ae Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 30 Nov 2023 23:03:44 +0100 Subject: [PATCH 05/30] Adding containedctx and contextcheck to implicitly disabled Signed-off-by: Yolan Romailler --- .golangci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index bef04abe59d..a220c0bf9d6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -38,6 +38,8 @@ linters: - unconvert - unused # these are implicitly disabled: + # - containedctx + # - contextcheck # - depguard # - dupl # - exhaustive From de5f90380cc3bcdbf80bd8ab661c51f103cd9d00 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 30 Nov 2023 23:25:10 +0100 Subject: [PATCH 06/30] Adding dupl as a linter (not for log filters) for code clone detection. Signed-off-by: Yolan Romailler --- .golangci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index a220c0bf9d6..6ff8ca3737c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -24,6 +24,7 @@ linters: - bidichk - bodyclose - dogsled + - dupl - errcheck - gci - gofumpt @@ -41,7 +42,6 @@ linters: # - containedctx # - contextcheck # - depguard - # - dupl # - exhaustive # - exportloopref # - funlen @@ -114,3 +114,6 @@ issues: text: 'G404' # G404: Insecure random number source (rand) linters: - gosec + - path: modules/logging/filters.go + linters: + - dupl From 1c345532682a900dc7e87481c893200babbc5612 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 30 Nov 2023 23:27:47 +0100 Subject: [PATCH 07/30] Adding decorder as a linter. Check declaration order and count of types, constants, variables and functions. Also adding cyclop to the list of implicitly disabled linters. Signed-off-by: Yolan Romailler --- .golangci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index 6ff8ca3737c..90f818287d1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -23,6 +23,7 @@ linters: - asciicheck - bidichk - bodyclose + - decorder - dogsled - dupl - errcheck @@ -41,6 +42,7 @@ linters: # these are implicitly disabled: # - containedctx # - contextcheck + # - cyclop # - depguard # - exhaustive # - exportloopref From 483800aaf758e962fa53c79eda00fc57c227f30c Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 30 Nov 2023 23:31:04 +0100 Subject: [PATCH 08/30] Adding dupword as a linter. Checks for duplicate words in the source code. Also fixed duplicate words in 3 files. Signed-off-by: Yolan Romailler --- .golangci.yml | 1 + caddyconfig/caddyfile/adapter.go | 2 +- logging.go | 2 +- modules/caddyhttp/reverseproxy/reverseproxy.go | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 90f818287d1..cf5fd792eb8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -26,6 +26,7 @@ linters: - decorder - dogsled - dupl + - dupword - errcheck - gci - gofumpt diff --git a/caddyconfig/caddyfile/adapter.go b/caddyconfig/caddyfile/adapter.go index d6ef602dca5..35add56e7e9 100644 --- a/caddyconfig/caddyfile/adapter.go +++ b/caddyconfig/caddyfile/adapter.go @@ -52,7 +52,7 @@ func (a Adapter) Adapt(body []byte, options map[string]any) ([]byte, []caddyconf return nil, warnings, err } - // lint check: see if input was properly formatted; sometimes messy files files parse + // lint check: see if input was properly formatted; sometimes messy files parse // successfully but result in logical errors (the Caddyfile is a bad format, I'm sorry) if warning, different := FormattingDifference(filename, body); different { warnings = append(warnings, warning) diff --git a/logging.go b/logging.go index 58d5b2d3f8a..9738a9e85bd 100644 --- a/logging.go +++ b/logging.go @@ -504,7 +504,7 @@ func (cl *CustomLog) loggerAllowed(name string, isModule bool) bool { // append a dot so that partial names don't match // (i.e. we don't want "foo.b" to match "foo.bar"); we // will also have to append a dot when we do HasPrefix - // below to compensate for when when namespaces are equal + // below to compensate for when namespaces are equal if name != "" && name != "*" && name != "." { name += "." } diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go index 1a76aef4c5b..ed91e3f96cd 100644 --- a/modules/caddyhttp/reverseproxy/reverseproxy.go +++ b/modules/caddyhttp/reverseproxy/reverseproxy.go @@ -1093,7 +1093,7 @@ func (h Handler) provisionUpstream(upstream *Upstream) { // if the passive health checker has a non-zero UnhealthyRequestCount // but the upstream has no MaxRequests set (they are the same thing, - // but the passive health checker is a default value for for upstreams + // but the passive health checker is a default value for upstreams // without MaxRequests), copy the value into this upstream, since the // value in the upstream (MaxRequests) is what is used during // availability checks From 6536bc2a7537be72454c361cac7a5534a15cca0d Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 30 Nov 2023 23:31:55 +0100 Subject: [PATCH 09/30] Adding durationcheck as a linter. Check for two durations multiplied together. Signed-off-by: Yolan Romailler --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index cf5fd792eb8..3680a4622d7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -27,6 +27,7 @@ linters: - dogsled - dupl - dupword + - durationcheck - errcheck - gci - gofumpt From 75912d61bc2926bdd6ec246c02dd09f400ba3071 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Fri, 1 Dec 2023 00:40:40 +0100 Subject: [PATCH 10/30] Adding errchkjson to implicitly disabled linters Signed-off-by: Yolan Romailler --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index 3680a4622d7..e1aebf7f502 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -46,6 +46,7 @@ linters: # - contextcheck # - cyclop # - depguard + # - errchkjson # - exhaustive # - exportloopref # - funlen From 2c516fab7820ed9a28dde615401d3ce24120185b Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Sat, 2 Dec 2023 12:21:09 +0100 Subject: [PATCH 11/30] Adding exhaustive as a linter. Check exhaustiveness of enum switch statements. Signed-off-by: Yolan Romailler --- .golangci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index e1aebf7f502..a551ddcc634 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -15,6 +15,8 @@ linters-settings: # If `true`, make the section order the same as the order of `sections`. # Default: false custom-order: true + exhaustive: + ignore-enum-types: reflect.Kind linters: disable-all: true @@ -29,6 +31,7 @@ linters: - dupword - durationcheck - errcheck + - exhaustive - gci - gofumpt - gosec @@ -47,7 +50,6 @@ linters: # - cyclop # - depguard # - errchkjson - # - exhaustive # - exportloopref # - funlen # - gci From 60246e775ebd9d5c396fdd386f09ea4dbe045da6 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Sat, 2 Dec 2023 12:23:05 +0100 Subject: [PATCH 12/30] Adding exportloopref as a linter. Checks for pointers to enclosing loop variables. Also adding exhaustruct to the list of implicitly disabled linters. Signed-off-by: Yolan Romailler --- .golangci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index a551ddcc634..50450a59f81 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -32,6 +32,7 @@ linters: - durationcheck - errcheck - exhaustive + - exportloopref - gci - gofumpt - gosec @@ -50,7 +51,7 @@ linters: # - cyclop # - depguard # - errchkjson - # - exportloopref + # - exhaustruct # - funlen # - gci # - gochecknoglobals From cac89c5017bdce2ac0997322e3cfe7e921257aa0 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Sat, 2 Dec 2023 12:25:11 +0100 Subject: [PATCH 13/30] Adding whitespace as a linter. Whitespace is a linter that checks for unnecessary newlines at the start and end of functions, if, for, etc. Patching the few issues it found too. Signed-off-by: Yolan Romailler --- .golangci.yml | 2 +- caddytest/caddytest.go | 1 - context.go | 3 --- modules/caddyhttp/encode/encode.go | 1 - modules/caddyhttp/reverseproxy/fastcgi/client.go | 1 - modules/caddyhttp/reverseproxy/httptransport.go | 1 - modules/caddytls/internalissuer.go | 1 - 7 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 50450a59f81..c7e3cb4fee0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -45,6 +45,7 @@ linters: - typecheck - unconvert - unused + - whitespace # these are implicitly disabled: # - containedctx # - contextcheck @@ -83,7 +84,6 @@ linters: # - stylecheck # - testpackage # - unparam - # - whitespace # - wsl run: diff --git a/caddytest/caddytest.go b/caddytest/caddytest.go index 26d3de660ab..666975140da 100644 --- a/caddytest/caddytest.go +++ b/caddytest/caddytest.go @@ -121,7 +121,6 @@ func (tc *Tester) initServer(rawConfig string, configType string) error { tc.t.Cleanup(func() { if tc.t.Failed() && tc.configLoaded { - res, err := http.Get(fmt.Sprintf("http://localhost:%d/config/", Default.AdminPort)) if err != nil { tc.t.Log("unable to read the current config") diff --git a/context.go b/context.go index 85978d49cd8..c14ec8e1cf7 100644 --- a/context.go +++ b/context.go @@ -164,7 +164,6 @@ func (ctx Context) LoadModule(structPointer any, fieldName string) (any, error) return nil, err } result = val - } else if isJSONRawMessage(typ.Elem()) { // val is `[]json.RawMessage` @@ -180,7 +179,6 @@ func (ctx Context) LoadModule(structPointer any, fieldName string) (any, error) all = append(all, val) } result = all - } else if typ.Elem().Kind() == reflect.Slice && isJSONRawMessage(typ.Elem().Elem()) { // val is `[][]json.RawMessage` @@ -201,7 +199,6 @@ func (ctx Context) LoadModule(structPointer any, fieldName string) (any, error) all = append(all, allInner) } result = all - } else if isModuleMapType(typ.Elem()) { // val is `[]map[string]json.RawMessage` diff --git a/modules/caddyhttp/encode/encode.go b/modules/caddyhttp/encode/encode.go index dc35fa245fc..8f733a3f27f 100644 --- a/modules/caddyhttp/encode/encode.go +++ b/modules/caddyhttp/encode/encode.go @@ -311,7 +311,6 @@ func (rw *responseWriter) Unwrap() http.ResponseWriter { func (rw *responseWriter) init() { if rw.Header().Get("Content-Encoding") == "" && isEncodeAllowed(rw.Header()) && rw.config.Match(rw) { - rw.w = rw.config.writerPools[rw.encodingName].Get().(Encoder) rw.w.Reset(rw.ResponseWriter) rw.Header().Del("Content-Length") // https://github.com/golang/go/issues/14975 diff --git a/modules/caddyhttp/reverseproxy/fastcgi/client.go b/modules/caddyhttp/reverseproxy/fastcgi/client.go index 04513dd85f3..d944c5778c1 100644 --- a/modules/caddyhttp/reverseproxy/fastcgi/client.go +++ b/modules/caddyhttp/reverseproxy/fastcgi/client.go @@ -221,7 +221,6 @@ func (c *client) Request(p map[string]string, req io.Reader) (resp *http.Respons if statusIsCut { resp.Status = statusInfo } - } else { resp.StatusCode = http.StatusOK } diff --git a/modules/caddyhttp/reverseproxy/httptransport.go b/modules/caddyhttp/reverseproxy/httptransport.go index 187bccc660c..acedacdaa99 100644 --- a/modules/caddyhttp/reverseproxy/httptransport.go +++ b/modules/caddyhttp/reverseproxy/httptransport.go @@ -556,7 +556,6 @@ func (t TLSConfig) MakeTLSClientConfig(ctx caddy.Context) (*tls.Config, error) { return nil, fmt.Errorf("failed reading ca cert: %v", err) } rootPool.AppendCertsFromPEM(pemData) - } cfg.RootCAs = rootPool } diff --git a/modules/caddytls/internalissuer.go b/modules/caddytls/internalissuer.go index 1cf2461ab7c..e3b9c07682e 100644 --- a/modules/caddytls/internalissuer.go +++ b/modules/caddytls/internalissuer.go @@ -178,7 +178,6 @@ func (iss *InternalIssuer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { return d.ArgErr() } iss.SignWithRoot = true - } } } From 6070fa463f996a4457f51c44a4976f023107302a Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Sat, 2 Dec 2023 12:27:46 +0100 Subject: [PATCH 14/30] Adding zerologlint as a linter. Detects the wrong usage of zerolog that a user forgets to dispatch with Send or Msg. Signed-off-by: Yolan Romailler --- .golangci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.golangci.yml b/.golangci.yml index c7e3cb4fee0..1c03c99f621 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -46,6 +46,7 @@ linters: - unconvert - unused - whitespace + - zerologlint # these are implicitly disabled: # - containedctx # - contextcheck From 915354f9ccb00a50ba5ece197bfe03c6b3a6803e Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Sat, 2 Dec 2023 12:29:24 +0100 Subject: [PATCH 15/30] Adding wastedassign as a linter. Finds wasted assignment statements. Adding wrapcheck to the list of implicitly disabled linters. Signed-off-by: Yolan Romailler --- .golangci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index 1c03c99f621..437765c0387 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -45,6 +45,7 @@ linters: - typecheck - unconvert - unused + - wastedassign - whitespace - zerologlint # these are implicitly disabled: @@ -85,6 +86,7 @@ linters: # - stylecheck # - testpackage # - unparam + # - wrapcheck # - wsl run: From 714476cd67b0c80152bf04acd82cb3698d1470a4 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Sat, 2 Dec 2023 13:38:17 +0100 Subject: [PATCH 16/30] Adding errname as a linter. Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error. Also fixing one case in reverse proxy and exporting the error to allow error matching against it. Signed-off-by: Yolan Romailler --- .golangci.yml | 1 + modules/caddyhttp/reverseproxy/reverseproxy.go | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 437765c0387..531fdcd799d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -31,6 +31,7 @@ linters: - dupword - durationcheck - errcheck + - errname - exhaustive - exportloopref - gci diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go index ed91e3f96cd..16e4d4d6e19 100644 --- a/modules/caddyhttp/reverseproxy/reverseproxy.go +++ b/modules/caddyhttp/reverseproxy/reverseproxy.go @@ -487,7 +487,7 @@ func (h *Handler) proxyLoopIteration(r *http.Request, origReq *http.Request, w h upstream := h.LoadBalancing.SelectionPolicy.Select(upstreams, r, w) if upstream == nil { if proxyErr == nil { - proxyErr = caddyhttp.Error(http.StatusServiceUnavailable, noUpstreamsAvailable) + proxyErr = caddyhttp.Error(http.StatusServiceUnavailable, ErrNoUpstream) } if !h.LoadBalancing.tryAgain(h.ctx, start, retries, proxyErr, r) { return true, proxyErr @@ -1037,7 +1037,7 @@ func (lb LoadBalancing) tryAgain(ctx caddy.Context, start time.Time, retries int // we have to assume the upstream received the request, and // retries need to be carefully decided, because some requests // are not idempotent - if !isDialError && !(isHandlerError && errors.Is(herr, noUpstreamsAvailable)) { + if !isDialError && !(isHandlerError && errors.Is(herr, ErrNoUpstream)) { if lb.RetryMatch == nil && req.Method != "GET" { // by default, don't retry requests if they aren't GET return false @@ -1446,7 +1446,8 @@ func (c ignoreClientGoneContext) Err() error { // from the proxy handler. const proxyHandleResponseContextCtxKey caddy.CtxKey = "reverse_proxy_handle_response_context" -var noUpstreamsAvailable = fmt.Errorf("no upstreams available") +// ErrNoUpstream occurs when there are no upstream available. +var ErrNoUpstream = fmt.Errorf("no upstreams available") // Interface guards var ( From be506d57ffe1fc56df1606bfc9188235ef6c1786 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Sat, 2 Dec 2023 13:55:14 +0100 Subject: [PATCH 17/30] Updating the list of implicitly disabled linters. To have all the current linters that aren't archived or deprecated as per golangci-lint.run/usage/linters/. Signed-off-by: Yolan Romailler --- .golangci.yml | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 531fdcd799d..cd230a2dc18 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -55,11 +55,18 @@ linters: # - cyclop # - depguard # - errchkjson + # - errorlint # - exhaustruct + # - execinquery + # - exhaustruct + # - forbidigo + # - forcetypeassert # - funlen - # - gci + # - ginkgolinter + # - gocheckcompilerdirectives # - gochecknoglobals # - gochecknoinits + # - gochecksumtype # - gocognit # - goconst # - gocritic @@ -67,26 +74,56 @@ linters: # - godot # - godox # - goerr113 - # - gofumpt + # - gofmt # - goheader - # - golint + # - goimports # - gomnd + # - gomoddirectives # - gomodguard # - goprintffuncname - # - interfacer + # - gosmopolitan + # - grouper + # - importas + # - inamedparam + # - interfacebloat + # - ireturn # - lll - # - maligned + # - loggercheck + # - maintidx + # - makezero + # - mirror + # - musttag # - nakedret # - nestif + # - nilerr + # - nilnil # - nlreturn # - noctx # - nolintlint + # - nonamedreturns + # - nosprintfhostport + # - paralleltest + # - perfsprint + # - predeclared + # - promlinter + # - protogetter + # - reassign + # - revive # - rowserrcheck - # - scopelint + # - sloglint # - sqlclosecheck # - stylecheck + # - tagalign + # - tagliatelle + # - tenv + # - testableexamples + # - testifylint # - testpackage + # - thelper + # - tparallel # - unparam + # - usestdlibvars + # - varnamelen # - wrapcheck # - wsl From 5290384af88ee3fdbaf50d8d4e7227391e3ee8ff Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Sat, 2 Dec 2023 17:49:47 +0100 Subject: [PATCH 18/30] Fix exhaustive linter on windows on svc.Cmd Signed-off-by: Yolan Romailler --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index cd230a2dc18..6afef4413e9 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,7 +16,7 @@ linters-settings: # Default: false custom-order: true exhaustive: - ignore-enum-types: reflect.Kind + ignore-enum-types: reflect.Kind|svc.Cmd linters: disable-all: true From 2663edd18582dcb6e56f575a514230ef6cfd1712 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 25 Jan 2024 12:51:34 +0100 Subject: [PATCH 19/30] Addressing code review comments --- modules/caddyhttp/reverseproxy/reverseproxy.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go index 10ee16889b3..201ff638bb4 100644 --- a/modules/caddyhttp/reverseproxy/reverseproxy.go +++ b/modules/caddyhttp/reverseproxy/reverseproxy.go @@ -487,7 +487,7 @@ func (h *Handler) proxyLoopIteration(r *http.Request, origReq *http.Request, w h upstream := h.LoadBalancing.SelectionPolicy.Select(upstreams, r, w) if upstream == nil { if proxyErr == nil { - proxyErr = caddyhttp.Error(http.StatusServiceUnavailable, ErrNoUpstream) + proxyErr = caddyhttp.Error(http.StatusServiceUnavailable, errNoUpstream) } if !h.LoadBalancing.tryAgain(h.ctx, start, retries, proxyErr, r) { return true, proxyErr @@ -1041,7 +1041,7 @@ func (lb LoadBalancing) tryAgain(ctx caddy.Context, start time.Time, retries int // we have to assume the upstream received the request, and // retries need to be carefully decided, because some requests // are not idempotent - if !isDialError && !(isHandlerError && errors.Is(herr, ErrNoUpstream)) { + if !isDialError && !(isHandlerError && errors.Is(herr, errNoUpstream)) { if lb.RetryMatch == nil && req.Method != "GET" { // by default, don't retry requests if they aren't GET return false @@ -1450,8 +1450,8 @@ func (c ignoreClientGoneContext) Err() error { // from the proxy handler. const proxyHandleResponseContextCtxKey caddy.CtxKey = "reverse_proxy_handle_response_context" -// ErrNoUpstream occurs when there are no upstream available. -var ErrNoUpstream = fmt.Errorf("no upstreams available") +// errNoUpstream occurs when there are no upstream available. +var errNoUpstream = fmt.Errorf("no upstreams available") // Interface guards var ( From ca35e7e2287e73fa2e99652ee385860f5bc9c4c9 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 25 Jan 2024 12:57:45 +0100 Subject: [PATCH 20/30] Adding sloglint as a linter. Ensure consistent code style when using log/slog. Signed-off-by: Yolan Romailler --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 6afef4413e9..3a1b11b16a4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -42,6 +42,7 @@ linters: - ineffassign - misspell - prealloc + - sloglint - staticcheck - typecheck - unconvert @@ -110,7 +111,6 @@ linters: # - reassign # - revive # - rowserrcheck - # - sloglint # - sqlclosecheck # - stylecheck # - tagalign From 68e025fd17f61acfdef8f3e88ea82dd26ca48d8a Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 25 Jan 2024 12:59:41 +0100 Subject: [PATCH 21/30] Adding gofmt as a linter. Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification. Signed-off-by: Yolan Romailler --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 3a1b11b16a4..3313298e61b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -35,6 +35,7 @@ linters: - exhaustive - exportloopref - gci + - gofmt - gofumpt - gosec - gosimple @@ -75,7 +76,6 @@ linters: # - godot # - godox # - goerr113 - # - gofmt # - goheader # - goimports # - gomnd From f8e2ddd21c548f9bf6278051190c049d904c098c Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 25 Jan 2024 13:01:20 +0100 Subject: [PATCH 22/30] Adding goimports as a linter. Check import statements are formatted according to the 'goimport' command. Signed-off-by: Yolan Romailler --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 3313298e61b..e9d1e494182 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -36,6 +36,7 @@ linters: - exportloopref - gci - gofmt + - goimports - gofumpt - gosec - gosimple @@ -77,7 +78,6 @@ linters: # - godox # - goerr113 # - goheader - # - goimports # - gomnd # - gomoddirectives # - gomodguard From 99c7ae085f304231fd1788bf381131069579eee8 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 25 Jan 2024 13:02:34 +0100 Subject: [PATCH 23/30] Adding importas as a linter. Enforces consistent import aliases. Signed-off-by: Yolan Romailler --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index e9d1e494182..1804e640c7f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -42,6 +42,7 @@ linters: - gosimple - govet - ineffassign + - importas - misspell - prealloc - sloglint @@ -84,7 +85,6 @@ linters: # - goprintffuncname # - gosmopolitan # - grouper - # - importas # - inamedparam # - interfacebloat # - ireturn From c6f49f81e791be6a5dcbeb26942781c807a9af5e Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 25 Jan 2024 13:07:54 +0100 Subject: [PATCH 24/30] Adding tparallel as a linter. Tparallel detects inappropriate usage of t.Parallel() method in Go test codes. Signed-off-by: Yolan Romailler --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 1804e640c7f..33cafe6c5e2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -47,6 +47,7 @@ linters: - prealloc - sloglint - staticcheck + - tparallel - typecheck - unconvert - unused @@ -120,7 +121,6 @@ linters: # - testifylint # - testpackage # - thelper - # - tparallel # - unparam # - usestdlibvars # - varnamelen From 00e5cdce4d8085f6b526f29deee41f90ed3ad9f2 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 25 Jan 2024 13:19:18 +0100 Subject: [PATCH 25/30] Adding testifylint as a linter. Checks proper usage of github.com/stretchr/testify. Signed-off-by: Yolan Romailler --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 33cafe6c5e2..b7e39731569 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -47,6 +47,7 @@ linters: - prealloc - sloglint - staticcheck + - testifylint - tparallel - typecheck - unconvert @@ -118,7 +119,6 @@ linters: # - tagliatelle # - tenv # - testableexamples - # - testifylint # - testpackage # - thelper # - unparam From e8dd76407033897406fa4fa4083994afa217c4ba Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 25 Jan 2024 13:20:47 +0100 Subject: [PATCH 26/30] Adding testableexamples as a linter. This linter checks if examples are testable (have an expected output). Signed-off-by: Yolan Romailler --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index b7e39731569..190177e411b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -47,6 +47,7 @@ linters: - prealloc - sloglint - staticcheck + - testableexamples - testifylint - tparallel - typecheck @@ -118,7 +119,6 @@ linters: # - tagalign # - tagliatelle # - tenv - # - testableexamples # - testpackage # - thelper # - unparam From a2182d981eabfbc00e529faa7a16829e386033e8 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 25 Jan 2024 13:21:47 +0100 Subject: [PATCH 27/30] Adding tenv as a linter. Tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17. Signed-off-by: Yolan Romailler --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 190177e411b..35220b1c91d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -47,6 +47,7 @@ linters: - prealloc - sloglint - staticcheck + - tenv - testableexamples - testifylint - tparallel @@ -118,7 +119,6 @@ linters: # - stylecheck # - tagalign # - tagliatelle - # - tenv # - testpackage # - thelper # - unparam From df496d7f8d64e07bcb27e594a2cd86e0479146f6 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 25 Jan 2024 13:24:19 +0100 Subject: [PATCH 28/30] Adding sqlclosecheck as a linter. Checks that sql.Rows, sql.Stmt, sqlx.NamedStmt, pgx.Query are closed. Signed-off-by: Yolan Romailler --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 35220b1c91d..a60c1fe1456 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -46,6 +46,7 @@ linters: - misspell - prealloc - sloglint + - sqlclosecheck - staticcheck - tenv - testableexamples @@ -115,7 +116,6 @@ linters: # - reassign # - revive # - rowserrcheck - # - sqlclosecheck # - stylecheck # - tagalign # - tagliatelle From 752e72714320967d3a9ea1d247f759a9111c5a61 Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 25 Jan 2024 13:28:28 +0100 Subject: [PATCH 29/30] Adding promlinter as a linter. Check Prometheus metrics naming via promlint. Signed-off-by: Yolan Romailler --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index a60c1fe1456..d144395dbda 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -45,6 +45,7 @@ linters: - importas - misspell - prealloc + - promlinter - sloglint - sqlclosecheck - staticcheck @@ -111,7 +112,6 @@ linters: # - paralleltest # - perfsprint # - predeclared - # - promlinter # - protogetter # - reassign # - revive From ebb0944d9b42a5957d748658500bb24b3a97fb1f Mon Sep 17 00:00:00 2001 From: Yolan Romailler Date: Thu, 25 Jan 2024 15:02:50 +0100 Subject: [PATCH 30/30] Use latest golangci-lint version in GHA. Signed-off-by: Yolan Romailler --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 7f65e7a7671..b1fda44c4d2 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -40,7 +40,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.54 + version: v1.55 # Workaround for https://github.com/golangci/golangci-lint-action/issues/135 skip-pkg-cache: true