Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enabling a few more linters #5961

Merged
merged 33 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d8ef1c0
Adding asciicheck as a linter
AnomalRoil Nov 30, 2023
722fa94
Adding bidichk as a linter
AnomalRoil Nov 30, 2023
f2e3019
Adding asasalint as a linter
AnomalRoil Nov 30, 2023
cf20b78
Adding doglsed as a linter
AnomalRoil Nov 30, 2023
79f24c0
Adding containedctx and contextcheck to implicitly disabled
AnomalRoil Nov 30, 2023
de5f903
Adding dupl as a linter (not for log filters)
AnomalRoil Nov 30, 2023
1c34553
Adding decorder as a linter.
AnomalRoil Nov 30, 2023
483800a
Adding dupword as a linter.
AnomalRoil Nov 30, 2023
6536bc2
Adding durationcheck as a linter.
AnomalRoil Nov 30, 2023
75912d6
Adding errchkjson to implicitly disabled linters
AnomalRoil Nov 30, 2023
2c516fa
Adding exhaustive as a linter.
AnomalRoil Dec 2, 2023
60246e7
Adding exportloopref as a linter.
AnomalRoil Dec 2, 2023
cac89c5
Adding whitespace as a linter.
AnomalRoil Dec 2, 2023
6070fa4
Adding zerologlint as a linter.
AnomalRoil Dec 2, 2023
915354f
Adding wastedassign as a linter.
AnomalRoil Dec 2, 2023
714476c
Adding errname as a linter.
AnomalRoil Dec 2, 2023
be506d5
Updating the list of implicitly disabled linters.
AnomalRoil Dec 2, 2023
5290384
Fix exhaustive linter on windows on svc.Cmd
AnomalRoil Dec 2, 2023
f28efb5
Merge branch 'master' into lint/moreismore
AnomalRoil Jan 12, 2024
2663edd
Addressing code review comments
AnomalRoil Jan 25, 2024
ca35e7e
Adding sloglint as a linter.
AnomalRoil Jan 25, 2024
68e025f
Adding gofmt as a linter.
AnomalRoil Jan 25, 2024
f8e2ddd
Adding goimports as a linter.
AnomalRoil Jan 25, 2024
99c7ae0
Adding importas as a linter.
AnomalRoil Jan 25, 2024
c6f49f8
Adding tparallel as a linter.
AnomalRoil Jan 25, 2024
00e5cdc
Adding testifylint as a linter.
AnomalRoil Jan 25, 2024
e8dd764
Adding testableexamples as a linter.
AnomalRoil Jan 25, 2024
a2182d9
Adding tenv as a linter.
AnomalRoil Jan 25, 2024
df496d7
Adding sqlclosecheck as a linter.
AnomalRoil Jan 25, 2024
752e727
Adding promlinter as a linter.
AnomalRoil Jan 25, 2024
dada8fd
Merging with latest master
AnomalRoil Jan 25, 2024
ebb0944
Use latest golangci-lint version in GHA.
AnomalRoil Jan 25, 2024
fe73311
Merge branch 'master' into lint/moreismore
francislavoie Jan 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
82 changes: 69 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,63 +15,116 @@ 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|svc.Cmd

linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- decorder
- dogsled
- dupl
- dupword
- durationcheck
- errcheck
- errname
- exhaustive
- exportloopref
- gci
- gofmt
- goimports
- gofumpt
- gosec
- gosimple
- govet
- ineffassign
- importas
- misspell
- prealloc
- promlinter
- sloglint
- sqlclosecheck
- staticcheck
- tenv
- testableexamples
- testifylint
- tparallel
- typecheck
- unconvert
- unused
- wastedassign
- whitespace
- zerologlint
# these are implicitly disabled:
# - asciicheck
# - containedctx
# - contextcheck
# - cyclop
# - depguard
# - dogsled
# - dupl
# - exhaustive
# - exportloopref
# - errchkjson
# - errorlint
# - exhaustruct
# - execinquery
# - exhaustruct
# - forbidigo
# - forcetypeassert
# - funlen
# - gci
# - ginkgolinter
# - gocheckcompilerdirectives
# - gochecknoglobals
# - gochecknoinits
# - gochecksumtype
# - gocognit
# - goconst
# - gocritic
# - gocyclo
# - godot
# - godox
# - goerr113
# - gofumpt
# - goheader
# - golint
# - gomnd
# - gomoddirectives
# - gomodguard
# - goprintffuncname
# - interfacer
# - gosmopolitan
# - grouper
# - inamedparam
# - interfacebloat
# - ireturn
# - lll
# - maligned
# - loggercheck
# - maintidx
# - makezero
# - mirror
# - musttag
# - nakedret
# - nestif
# - nilerr
# - nilnil
# - nlreturn
# - noctx
# - nolintlint
# - nonamedreturns
# - nosprintfhostport
# - paralleltest
# - perfsprint
# - predeclared
# - protogetter
# - reassign
# - revive
# - rowserrcheck
# - scopelint
# - sqlclosecheck
# - stylecheck
# - tagalign
# - tagliatelle
# - testpackage
# - thelper
# - unparam
# - whitespace
# - usestdlibvars
# - varnamelen
# - wrapcheck
# - wsl

run:
Expand Down Expand Up @@ -110,3 +163,6 @@ issues:
text: 'G404' # G404: Insecure random number source (rand)
linters:
- gosec
- path: modules/logging/filters.go
linters:
- dupl
2 changes: 1 addition & 1 deletion caddyconfig/caddyfile/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion caddytest/caddytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 0 additions & 3 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,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`

Expand All @@ -192,7 +191,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`

Expand All @@ -213,7 +211,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`

Expand Down
2 changes: 1 addition & 1 deletion logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,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
AnomalRoil marked this conversation as resolved.
Show resolved Hide resolved
// below to compensate for when namespaces are equal
if name != "" && name != "*" && name != "." {
name += "."
}
Expand Down
1 change: 0 additions & 1 deletion modules/caddyhttp/encode/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion modules/caddyhttp/reverseproxy/fastcgi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion modules/caddyhttp/reverseproxy/httptransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,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
}
Expand Down
9 changes: 5 additions & 4 deletions modules/caddyhttp/reverseproxy/reverseproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, 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
Expand Down Expand Up @@ -1097,7 +1097,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
Expand Down Expand Up @@ -1450,7 +1450,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 (
Expand Down
1 change: 0 additions & 1 deletion modules/caddytls/internalissuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ func (iss *InternalIssuer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
return d.ArgErr()
}
iss.SignWithRoot = true

}
}
return nil
Expand Down
Loading