@marcel91200 / caddy Mirror · read-only / commits / 2fe69a82
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 18:15 UTC

chore: enabling a few more linters (#5961)

Co-authored-by: Francis Lavoie <lavofr@gmail.com>

Yolan Romailler committed Jan 25, 2024 at 16:24 UTC 2fe69a828f9fcacc0160a576839d4b67c5730031
11 files changed +77 -28
.github/workflows/lint.yml
+1 -1
@@ -40,7 +40,7 @@ jobs:
40 - name: golangci-lint
41 uses: golangci/golangci-lint-action@v3
42 with:
43 - version: v1.54
43 + version: v1.55
44
45 # Workaround for https://github.com/golangci/golangci-lint-action/issues/135
46 skip-pkg-cache: true
.golangci.yml
+69 -13
@@ -15,35 +15,68 @@ linters-settings:
15 # If `true`, make the section order the same as the order of `sections`.
16 # Default: false
17 custom-order: true
18 + exhaustive:
19 + ignore-enum-types: reflect.Kind|svc.Cmd
20
21 linters:
22 disable-all: true
23 enable:
24 + - asasalint
25 + - asciicheck
26 + - bidichk
27 - bodyclose
28 + - decorder
29 + - dogsled
30 + - dupl
31 + - dupword
32 + - durationcheck
33 - errcheck
34 + - errname
35 + - exhaustive
36 + - exportloopref
37 - gci
38 + - gofmt
39 + - goimports
40 - gofumpt
41 - gosec
42 - gosimple
43 - govet
44 - ineffassign
45 + - importas
46 - misspell
47 - prealloc
48 + - promlinter
49 + - sloglint
50 + - sqlclosecheck
51 - staticcheck
52 + - tenv
53 + - testableexamples
54 + - testifylint
55 + - tparallel
56 - typecheck
57 - unconvert
58 - unused
59 + - wastedassign
60 + - whitespace
61 + - zerologlint
62 # these are implicitly disabled:
37 - # - asciicheck
63 + # - containedctx
64 + # - contextcheck
65 + # - cyclop
66 # - depguard
39 - # - dogsled
40 - # - dupl
41 - # - exhaustive
42 - # - exportloopref
67 + # - errchkjson
68 + # - errorlint
69 + # - exhaustruct
70 + # - execinquery
71 + # - exhaustruct
72 + # - forbidigo
73 + # - forcetypeassert
74 # - funlen
44 - # - gci
75 + # - ginkgolinter
76 + # - gocheckcompilerdirectives
77 # - gochecknoglobals
78 # - gochecknoinits
79 + # - gochecksumtype
80 # - gocognit
81 # - goconst
82 # - gocritic
@@ -51,27 +84,47 @@ linters:
84 # - godot
85 # - godox
86 # - goerr113
54 - # - gofumpt
87 # - goheader
56 - # - golint
88 # - gomnd
89 + # - gomoddirectives
90 # - gomodguard
91 # - goprintffuncname
60 - # - interfacer
92 + # - gosmopolitan
93 + # - grouper
94 + # - inamedparam
95 + # - interfacebloat
96 + # - ireturn
97 # - lll
62 - # - maligned
98 + # - loggercheck
99 + # - maintidx
100 + # - makezero
101 + # - mirror
102 + # - musttag
103 # - nakedret
104 # - nestif
105 + # - nilerr
106 + # - nilnil
107 # - nlreturn
108 # - noctx
109 # - nolintlint
110 + # - nonamedreturns
111 + # - nosprintfhostport
112 + # - paralleltest
113 + # - perfsprint
114 + # - predeclared
115 + # - protogetter
116 + # - reassign
117 + # - revive
118 # - rowserrcheck
69 - # - scopelint
70 - # - sqlclosecheck
119 # - stylecheck
120 + # - tagalign
121 + # - tagliatelle
122 # - testpackage
123 + # - thelper
124 # - unparam
74 - # - whitespace
125 + # - usestdlibvars
126 + # - varnamelen
127 + # - wrapcheck
128 # - wsl
129
130 run:
@@ -110,3 +163,6 @@ issues:
163 text: 'G404' # G404: Insecure random number source (rand)
164 linters:
165 - gosec
166 + - path: modules/logging/filters.go
167 + linters:
168 + - dupl
caddyconfig/caddyfile/adapter.go
+1 -1
@@ -52,7 +52,7 @@ func (a Adapter) Adapt(body []byte, options map[string]any) ([]byte, []caddyconf
52 return nil, warnings, err
53 }
54
55 - // lint check: see if input was properly formatted; sometimes messy files files parse
55 + // lint check: see if input was properly formatted; sometimes messy files parse
56 // successfully but result in logical errors (the Caddyfile is a bad format, I'm sorry)
57 if warning, different := FormattingDifference(filename, body); different {
58 warnings = append(warnings, warning)
caddytest/caddytest.go
-1
@@ -121,7 +121,6 @@ func (tc *Tester) initServer(rawConfig string, configType string) error {
121
122 tc.t.Cleanup(func() {
123 if tc.t.Failed() && tc.configLoaded {
124 -
124 res, err := http.Get(fmt.Sprintf("http://localhost:%d/config/", Default.AdminPort))
125 if err != nil {
126 tc.t.Log("unable to read the current config")
context.go
-3
@@ -176,7 +176,6 @@ func (ctx Context) LoadModule(structPointer any, fieldName string) (any, error)
176 return nil, err
177 }
178 result = val
179 -
179 } else if isJSONRawMessage(typ.Elem()) {
180 // val is `[]json.RawMessage`
181
@@ -192,7 +191,6 @@ func (ctx Context) LoadModule(structPointer any, fieldName string) (any, error)
191 all = append(all, val)
192 }
193 result = all
195 -
194 } else if typ.Elem().Kind() == reflect.Slice && isJSONRawMessage(typ.Elem().Elem()) {
195 // val is `[][]json.RawMessage`
196
@@ -213,7 +211,6 @@ func (ctx Context) LoadModule(structPointer any, fieldName string) (any, error)
211 all = append(all, allInner)
212 }
213 result = all
216 -
214 } else if isModuleMapType(typ.Elem()) {
215 // val is `[]map[string]json.RawMessage`
216
logging.go
+1 -1
@@ -517,7 +517,7 @@ func (cl *CustomLog) loggerAllowed(name string, isModule bool) bool {
517 // append a dot so that partial names don't match
518 // (i.e. we don't want "foo.b" to match "foo.bar"); we
519 // will also have to append a dot when we do HasPrefix
520 - // below to compensate for when when namespaces are equal
520 + // below to compensate for when namespaces are equal
521 if name != "" && name != "*" && name != "." {
522 name += "."
523 }
modules/caddyhttp/encode/encode.go
-1
@@ -311,7 +311,6 @@ func (rw *responseWriter) Unwrap() http.ResponseWriter {
311 func (rw *responseWriter) init() {
312 if rw.Header().Get("Content-Encoding") == "" && isEncodeAllowed(rw.Header()) &&
313 rw.config.Match(rw) {
314 -
314 rw.w = rw.config.writerPools[rw.encodingName].Get().(Encoder)
315 rw.w.Reset(rw.ResponseWriter)
316 rw.Header().Del("Content-Length") // https://github.com/golang/go/issues/14975
modules/caddyhttp/reverseproxy/fastcgi/client.go
-1
@@ -221,7 +221,6 @@ func (c *client) Request(p map[string]string, req io.Reader) (resp *http.Respons
221 if statusIsCut {
222 resp.Status = statusInfo
223 }
224 -
224 } else {
225 resp.StatusCode = http.StatusOK
226 }
modules/caddyhttp/reverseproxy/httptransport.go
-1
@@ -560,7 +560,6 @@ func (t TLSConfig) MakeTLSClientConfig(ctx caddy.Context) (*tls.Config, error) {
560 return nil, fmt.Errorf("failed reading ca cert: %v", err)
561 }
562 rootPool.AppendCertsFromPEM(pemData)
563 -
563 }
564 cfg.RootCAs = rootPool
565 }
modules/caddyhttp/reverseproxy/reverseproxy.go
+5 -4
@@ -487,7 +487,7 @@ func (h *Handler) proxyLoopIteration(r *http.Request, origReq *http.Request, w h
487 upstream := h.LoadBalancing.SelectionPolicy.Select(upstreams, r, w)
488 if upstream == nil {
489 if proxyErr == nil {
490 - proxyErr = caddyhttp.Error(http.StatusServiceUnavailable, noUpstreamsAvailable)
490 + proxyErr = caddyhttp.Error(http.StatusServiceUnavailable, errNoUpstream)
491 }
492 if !h.LoadBalancing.tryAgain(h.ctx, start, retries, proxyErr, r) {
493 return true, proxyErr
@@ -1041,7 +1041,7 @@ func (lb LoadBalancing) tryAgain(ctx caddy.Context, start time.Time, retries int
1041 // we have to assume the upstream received the request, and
1042 // retries need to be carefully decided, because some requests
1043 // are not idempotent
1044 - if !isDialError && !(isHandlerError && errors.Is(herr, noUpstreamsAvailable)) {
1044 + if !isDialError && !(isHandlerError && errors.Is(herr, errNoUpstream)) {
1045 if lb.RetryMatch == nil && req.Method != "GET" {
1046 // by default, don't retry requests if they aren't GET
1047 return false
@@ -1097,7 +1097,7 @@ func (h Handler) provisionUpstream(upstream *Upstream) {
1097
1098 // if the passive health checker has a non-zero UnhealthyRequestCount
1099 // but the upstream has no MaxRequests set (they are the same thing,
1100 - // but the passive health checker is a default value for for upstreams
1100 + // but the passive health checker is a default value for upstreams
1101 // without MaxRequests), copy the value into this upstream, since the
1102 // value in the upstream (MaxRequests) is what is used during
1103 // availability checks
@@ -1450,7 +1450,8 @@ func (c ignoreClientGoneContext) Err() error {
1450 // from the proxy handler.
1451 const proxyHandleResponseContextCtxKey caddy.CtxKey = "reverse_proxy_handle_response_context"
1452
1453 -var noUpstreamsAvailable = fmt.Errorf("no upstreams available")
1453 +// errNoUpstream occurs when there are no upstream available.
1454 +var errNoUpstream = fmt.Errorf("no upstreams available")
1455
1456 // Interface guards
1457 var (
modules/caddytls/internalissuer.go
-1
@@ -178,7 +178,6 @@ func (iss *InternalIssuer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
178 return d.ArgErr()
179 }
180 iss.SignWithRoot = true
181 -
181 }
182 }
183 return nil