mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
chore: enabling a few more linters (#5961)
Co-authored-by: Francis Lavoie <lavofr@gmail.com>
This commit is contained in:
parent
c369df5c37
commit
2fe69a828f
11 changed files with 77 additions and 28 deletions
2
.github/workflows/lint.yml
vendored
2
.github/workflows/lint.yml
vendored
|
@ -40,7 +40,7 @@ jobs:
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v3
|
uses: golangci/golangci-lint-action@v3
|
||||||
with:
|
with:
|
||||||
version: v1.54
|
version: v1.55
|
||||||
|
|
||||||
# Workaround for https://github.com/golangci/golangci-lint-action/issues/135
|
# Workaround for https://github.com/golangci/golangci-lint-action/issues/135
|
||||||
skip-pkg-cache: true
|
skip-pkg-cache: true
|
||||||
|
|
|
@ -15,35 +15,68 @@ linters-settings:
|
||||||
# If `true`, make the section order the same as the order of `sections`.
|
# If `true`, make the section order the same as the order of `sections`.
|
||||||
# Default: false
|
# Default: false
|
||||||
custom-order: true
|
custom-order: true
|
||||||
|
exhaustive:
|
||||||
|
ignore-enum-types: reflect.Kind|svc.Cmd
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
disable-all: true
|
disable-all: true
|
||||||
enable:
|
enable:
|
||||||
|
- asasalint
|
||||||
|
- asciicheck
|
||||||
|
- bidichk
|
||||||
- bodyclose
|
- bodyclose
|
||||||
|
- decorder
|
||||||
|
- dogsled
|
||||||
|
- dupl
|
||||||
|
- dupword
|
||||||
|
- durationcheck
|
||||||
- errcheck
|
- errcheck
|
||||||
|
- errname
|
||||||
|
- exhaustive
|
||||||
|
- exportloopref
|
||||||
- gci
|
- gci
|
||||||
|
- gofmt
|
||||||
|
- goimports
|
||||||
- gofumpt
|
- gofumpt
|
||||||
- gosec
|
- gosec
|
||||||
- gosimple
|
- gosimple
|
||||||
- govet
|
- govet
|
||||||
- ineffassign
|
- ineffassign
|
||||||
|
- importas
|
||||||
- misspell
|
- misspell
|
||||||
- prealloc
|
- prealloc
|
||||||
|
- promlinter
|
||||||
|
- sloglint
|
||||||
|
- sqlclosecheck
|
||||||
- staticcheck
|
- staticcheck
|
||||||
|
- tenv
|
||||||
|
- testableexamples
|
||||||
|
- testifylint
|
||||||
|
- tparallel
|
||||||
- typecheck
|
- typecheck
|
||||||
- unconvert
|
- unconvert
|
||||||
- unused
|
- unused
|
||||||
|
- wastedassign
|
||||||
|
- whitespace
|
||||||
|
- zerologlint
|
||||||
# these are implicitly disabled:
|
# these are implicitly disabled:
|
||||||
# - asciicheck
|
# - containedctx
|
||||||
|
# - contextcheck
|
||||||
|
# - cyclop
|
||||||
# - depguard
|
# - depguard
|
||||||
# - dogsled
|
# - errchkjson
|
||||||
# - dupl
|
# - errorlint
|
||||||
# - exhaustive
|
# - exhaustruct
|
||||||
# - exportloopref
|
# - execinquery
|
||||||
|
# - exhaustruct
|
||||||
|
# - forbidigo
|
||||||
|
# - forcetypeassert
|
||||||
# - funlen
|
# - funlen
|
||||||
# - gci
|
# - ginkgolinter
|
||||||
|
# - gocheckcompilerdirectives
|
||||||
# - gochecknoglobals
|
# - gochecknoglobals
|
||||||
# - gochecknoinits
|
# - gochecknoinits
|
||||||
|
# - gochecksumtype
|
||||||
# - gocognit
|
# - gocognit
|
||||||
# - goconst
|
# - goconst
|
||||||
# - gocritic
|
# - gocritic
|
||||||
|
@ -51,27 +84,47 @@ linters:
|
||||||
# - godot
|
# - godot
|
||||||
# - godox
|
# - godox
|
||||||
# - goerr113
|
# - goerr113
|
||||||
# - gofumpt
|
|
||||||
# - goheader
|
# - goheader
|
||||||
# - golint
|
|
||||||
# - gomnd
|
# - gomnd
|
||||||
|
# - gomoddirectives
|
||||||
# - gomodguard
|
# - gomodguard
|
||||||
# - goprintffuncname
|
# - goprintffuncname
|
||||||
# - interfacer
|
# - gosmopolitan
|
||||||
|
# - grouper
|
||||||
|
# - inamedparam
|
||||||
|
# - interfacebloat
|
||||||
|
# - ireturn
|
||||||
# - lll
|
# - lll
|
||||||
# - maligned
|
# - loggercheck
|
||||||
|
# - maintidx
|
||||||
|
# - makezero
|
||||||
|
# - mirror
|
||||||
|
# - musttag
|
||||||
# - nakedret
|
# - nakedret
|
||||||
# - nestif
|
# - nestif
|
||||||
|
# - nilerr
|
||||||
|
# - nilnil
|
||||||
# - nlreturn
|
# - nlreturn
|
||||||
# - noctx
|
# - noctx
|
||||||
# - nolintlint
|
# - nolintlint
|
||||||
|
# - nonamedreturns
|
||||||
|
# - nosprintfhostport
|
||||||
|
# - paralleltest
|
||||||
|
# - perfsprint
|
||||||
|
# - predeclared
|
||||||
|
# - protogetter
|
||||||
|
# - reassign
|
||||||
|
# - revive
|
||||||
# - rowserrcheck
|
# - rowserrcheck
|
||||||
# - scopelint
|
|
||||||
# - sqlclosecheck
|
|
||||||
# - stylecheck
|
# - stylecheck
|
||||||
|
# - tagalign
|
||||||
|
# - tagliatelle
|
||||||
# - testpackage
|
# - testpackage
|
||||||
|
# - thelper
|
||||||
# - unparam
|
# - unparam
|
||||||
# - whitespace
|
# - usestdlibvars
|
||||||
|
# - varnamelen
|
||||||
|
# - wrapcheck
|
||||||
# - wsl
|
# - wsl
|
||||||
|
|
||||||
run:
|
run:
|
||||||
|
@ -110,3 +163,6 @@ issues:
|
||||||
text: 'G404' # G404: Insecure random number source (rand)
|
text: 'G404' # G404: Insecure random number source (rand)
|
||||||
linters:
|
linters:
|
||||||
- gosec
|
- gosec
|
||||||
|
- path: modules/logging/filters.go
|
||||||
|
linters:
|
||||||
|
- dupl
|
||||||
|
|
|
@ -52,7 +52,7 @@ func (a Adapter) Adapt(body []byte, options map[string]any) ([]byte, []caddyconf
|
||||||
return nil, warnings, err
|
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)
|
// successfully but result in logical errors (the Caddyfile is a bad format, I'm sorry)
|
||||||
if warning, different := FormattingDifference(filename, body); different {
|
if warning, different := FormattingDifference(filename, body); different {
|
||||||
warnings = append(warnings, warning)
|
warnings = append(warnings, warning)
|
||||||
|
|
|
@ -121,7 +121,6 @@ func (tc *Tester) initServer(rawConfig string, configType string) error {
|
||||||
|
|
||||||
tc.t.Cleanup(func() {
|
tc.t.Cleanup(func() {
|
||||||
if tc.t.Failed() && tc.configLoaded {
|
if tc.t.Failed() && tc.configLoaded {
|
||||||
|
|
||||||
res, err := http.Get(fmt.Sprintf("http://localhost:%d/config/", Default.AdminPort))
|
res, err := http.Get(fmt.Sprintf("http://localhost:%d/config/", Default.AdminPort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tc.t.Log("unable to read the current config")
|
tc.t.Log("unable to read the current config")
|
||||||
|
|
|
@ -176,7 +176,6 @@ func (ctx Context) LoadModule(structPointer any, fieldName string) (any, error)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
result = val
|
result = val
|
||||||
|
|
||||||
} else if isJSONRawMessage(typ.Elem()) {
|
} else if isJSONRawMessage(typ.Elem()) {
|
||||||
// val is `[]json.RawMessage`
|
// val is `[]json.RawMessage`
|
||||||
|
|
||||||
|
@ -192,7 +191,6 @@ func (ctx Context) LoadModule(structPointer any, fieldName string) (any, error)
|
||||||
all = append(all, val)
|
all = append(all, val)
|
||||||
}
|
}
|
||||||
result = all
|
result = all
|
||||||
|
|
||||||
} else if typ.Elem().Kind() == reflect.Slice && isJSONRawMessage(typ.Elem().Elem()) {
|
} else if typ.Elem().Kind() == reflect.Slice && isJSONRawMessage(typ.Elem().Elem()) {
|
||||||
// val is `[][]json.RawMessage`
|
// val is `[][]json.RawMessage`
|
||||||
|
|
||||||
|
@ -213,7 +211,6 @@ func (ctx Context) LoadModule(structPointer any, fieldName string) (any, error)
|
||||||
all = append(all, allInner)
|
all = append(all, allInner)
|
||||||
}
|
}
|
||||||
result = all
|
result = all
|
||||||
|
|
||||||
} else if isModuleMapType(typ.Elem()) {
|
} else if isModuleMapType(typ.Elem()) {
|
||||||
// val is `[]map[string]json.RawMessage`
|
// val is `[]map[string]json.RawMessage`
|
||||||
|
|
||||||
|
|
|
@ -517,7 +517,7 @@ func (cl *CustomLog) loggerAllowed(name string, isModule bool) bool {
|
||||||
// append a dot so that partial names don't match
|
// append a dot so that partial names don't match
|
||||||
// (i.e. we don't want "foo.b" to match "foo.bar"); we
|
// (i.e. we don't want "foo.b" to match "foo.bar"); we
|
||||||
// will also have to append a dot when we do HasPrefix
|
// 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 != "." {
|
if name != "" && name != "*" && name != "." {
|
||||||
name += "."
|
name += "."
|
||||||
}
|
}
|
||||||
|
|
|
@ -311,7 +311,6 @@ func (rw *responseWriter) Unwrap() http.ResponseWriter {
|
||||||
func (rw *responseWriter) init() {
|
func (rw *responseWriter) init() {
|
||||||
if rw.Header().Get("Content-Encoding") == "" && isEncodeAllowed(rw.Header()) &&
|
if rw.Header().Get("Content-Encoding") == "" && isEncodeAllowed(rw.Header()) &&
|
||||||
rw.config.Match(rw) {
|
rw.config.Match(rw) {
|
||||||
|
|
||||||
rw.w = rw.config.writerPools[rw.encodingName].Get().(Encoder)
|
rw.w = rw.config.writerPools[rw.encodingName].Get().(Encoder)
|
||||||
rw.w.Reset(rw.ResponseWriter)
|
rw.w.Reset(rw.ResponseWriter)
|
||||||
rw.Header().Del("Content-Length") // https://github.com/golang/go/issues/14975
|
rw.Header().Del("Content-Length") // https://github.com/golang/go/issues/14975
|
||||||
|
|
|
@ -221,7 +221,6 @@ func (c *client) Request(p map[string]string, req io.Reader) (resp *http.Respons
|
||||||
if statusIsCut {
|
if statusIsCut {
|
||||||
resp.Status = statusInfo
|
resp.Status = statusInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
resp.StatusCode = http.StatusOK
|
resp.StatusCode = http.StatusOK
|
||||||
}
|
}
|
||||||
|
|
|
@ -560,7 +560,6 @@ func (t TLSConfig) MakeTLSClientConfig(ctx caddy.Context) (*tls.Config, error) {
|
||||||
return nil, fmt.Errorf("failed reading ca cert: %v", err)
|
return nil, fmt.Errorf("failed reading ca cert: %v", err)
|
||||||
}
|
}
|
||||||
rootPool.AppendCertsFromPEM(pemData)
|
rootPool.AppendCertsFromPEM(pemData)
|
||||||
|
|
||||||
}
|
}
|
||||||
cfg.RootCAs = rootPool
|
cfg.RootCAs = rootPool
|
||||||
}
|
}
|
||||||
|
|
|
@ -487,7 +487,7 @@ func (h *Handler) proxyLoopIteration(r *http.Request, origReq *http.Request, w h
|
||||||
upstream := h.LoadBalancing.SelectionPolicy.Select(upstreams, r, w)
|
upstream := h.LoadBalancing.SelectionPolicy.Select(upstreams, r, w)
|
||||||
if upstream == nil {
|
if upstream == nil {
|
||||||
if proxyErr == 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) {
|
if !h.LoadBalancing.tryAgain(h.ctx, start, retries, proxyErr, r) {
|
||||||
return true, proxyErr
|
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
|
// we have to assume the upstream received the request, and
|
||||||
// retries need to be carefully decided, because some requests
|
// retries need to be carefully decided, because some requests
|
||||||
// are not idempotent
|
// are not idempotent
|
||||||
if !isDialError && !(isHandlerError && errors.Is(herr, noUpstreamsAvailable)) {
|
if !isDialError && !(isHandlerError && errors.Is(herr, errNoUpstream)) {
|
||||||
if lb.RetryMatch == nil && req.Method != "GET" {
|
if lb.RetryMatch == nil && req.Method != "GET" {
|
||||||
// by default, don't retry requests if they aren't GET
|
// by default, don't retry requests if they aren't GET
|
||||||
return false
|
return false
|
||||||
|
@ -1097,7 +1097,7 @@ func (h Handler) provisionUpstream(upstream *Upstream) {
|
||||||
|
|
||||||
// if the passive health checker has a non-zero UnhealthyRequestCount
|
// if the passive health checker has a non-zero UnhealthyRequestCount
|
||||||
// but the upstream has no MaxRequests set (they are the same thing,
|
// 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
|
// without MaxRequests), copy the value into this upstream, since the
|
||||||
// value in the upstream (MaxRequests) is what is used during
|
// value in the upstream (MaxRequests) is what is used during
|
||||||
// availability checks
|
// availability checks
|
||||||
|
@ -1450,7 +1450,8 @@ func (c ignoreClientGoneContext) Err() error {
|
||||||
// from the proxy handler.
|
// from the proxy handler.
|
||||||
const proxyHandleResponseContextCtxKey caddy.CtxKey = "reverse_proxy_handle_response_context"
|
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
|
// Interface guards
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -178,7 +178,6 @@ func (iss *InternalIssuer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
return d.ArgErr()
|
return d.ArgErr()
|
||||||
}
|
}
|
||||||
iss.SignWithRoot = true
|
iss.SignWithRoot = true
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue