Skip to content

Commit e039a5b

Browse files
authored
chore: upgrade .golangci.yml and workflow to v2 (#6924)
* chore: upgrade .golangci.yml and workflow to v2 run `golangci-lint fmt` Signed-off-by: Mohammed Al Sahaf <[email protected]> * run `golangci-lint run --fix` Signed-off-by: Mohammed Al Sahaf <[email protected]> * more lint fixes Signed-off-by: Mohammed Al Sahaf <[email protected]> * bring back comments to .golangci.yml Signed-off-by: Mohammed Al Sahaf <[email protected]> * appease the linter some more Signed-off-by: Mohammed Al Sahaf <[email protected]> * oops Signed-off-by: Mohammed Al Sahaf <[email protected]> * use embedded structs Signed-off-by: Mohammed Al Sahaf <[email protected]> * use embedded structs where they were used before Signed-off-by: Mohammed Al Sahaf <[email protected]> * disable rule `-QF1006` Signed-off-by: Mohammed Al Sahaf <[email protected]> * missed a spot Signed-off-by: Mohammed Al Sahaf <[email protected]> --------- Signed-off-by: Mohammed Al Sahaf <[email protected]>
1 parent 5b2eb66 commit e039a5b

33 files changed

+148
-213
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
check-latest: true
5252

5353
- name: golangci-lint
54-
uses: golangci/golangci-lint-action@v6
54+
uses: golangci/golangci-lint-action@v7
5555
with:
5656
version: latest
5757

.golangci.yml

Lines changed: 87 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
linters-settings:
2-
errcheck:
3-
exclude-functions:
4-
- fmt.*
5-
- (go.uber.org/zap/zapcore.ObjectEncoder).AddObject
6-
- (go.uber.org/zap/zapcore.ObjectEncoder).AddArray
7-
gci:
8-
sections:
9-
- standard # Standard section: captures all standard packages.
10-
- default # Default section: contains all imports that could not be matched to another section type.
11-
- prefix(github.com/caddyserver/caddy/v2/cmd) # ensure that this is always at the top and always has a line break.
12-
- prefix(github.com/caddyserver/caddy) # Custom section: groups all imports with the specified Prefix.
13-
# Skip generated files.
14-
# Default: true
15-
skip-generated: true
16-
# Enable custom order of sections.
17-
# If `true`, make the section order the same as the order of `sections`.
18-
# Default: false
19-
custom-order: true
20-
exhaustive:
21-
ignore-enum-types: reflect.Kind|svc.Cmd
22-
1+
version: "2"
2+
run:
3+
issues-exit-code: 1
4+
tests: false
5+
output:
6+
formats:
7+
text:
8+
path: stdout
9+
print-linter-name: true
10+
print-issued-lines: true
2311
linters:
24-
disable-all: true
12+
default: none
2513
enable:
2614
- asasalint
2715
- asciicheck
@@ -35,148 +23,96 @@ linters:
3523
- errcheck
3624
- errname
3725
- exhaustive
38-
- gci
39-
- gofmt
40-
- goimports
41-
- gofumpt
4226
- gosec
43-
- gosimple
4427
- govet
45-
- ineffassign
4628
- importas
29+
- ineffassign
4730
- misspell
4831
- prealloc
4932
- promlinter
5033
- sloglint
5134
- sqlclosecheck
5235
- staticcheck
53-
- tenv
5436
- testableexamples
5537
- testifylint
5638
- tparallel
57-
- typecheck
5839
- unconvert
5940
- unused
6041
- wastedassign
6142
- whitespace
6243
- zerologlint
63-
# these are implicitly disabled:
64-
# - containedctx
65-
# - contextcheck
66-
# - cyclop
67-
# - depguard
68-
# - errchkjson
69-
# - errorlint
70-
# - exhaustruct
71-
# - execinquery
72-
# - exhaustruct
73-
# - forbidigo
74-
# - forcetypeassert
75-
# - funlen
76-
# - ginkgolinter
77-
# - gocheckcompilerdirectives
78-
# - gochecknoglobals
79-
# - gochecknoinits
80-
# - gochecksumtype
81-
# - gocognit
82-
# - goconst
83-
# - gocritic
84-
# - gocyclo
85-
# - godot
86-
# - godox
87-
# - goerr113
88-
# - goheader
89-
# - gomnd
90-
# - gomoddirectives
91-
# - gomodguard
92-
# - goprintffuncname
93-
# - gosmopolitan
94-
# - grouper
95-
# - inamedparam
96-
# - interfacebloat
97-
# - ireturn
98-
# - lll
99-
# - loggercheck
100-
# - maintidx
101-
# - makezero
102-
# - mirror
103-
# - musttag
104-
# - nakedret
105-
# - nestif
106-
# - nilerr
107-
# - nilnil
108-
# - nlreturn
109-
# - noctx
110-
# - nolintlint
111-
# - nonamedreturns
112-
# - nosprintfhostport
113-
# - paralleltest
114-
# - perfsprint
115-
# - predeclared
116-
# - protogetter
117-
# - reassign
118-
# - revive
119-
# - rowserrcheck
120-
# - stylecheck
121-
# - tagalign
122-
# - tagliatelle
123-
# - testpackage
124-
# - thelper
125-
# - unparam
126-
# - usestdlibvars
127-
# - varnamelen
128-
# - wrapcheck
129-
# - wsl
130-
131-
run:
132-
# default concurrency is a available CPU number.
133-
# concurrency: 4 # explicitly omit this value to fully utilize available resources.
134-
timeout: 5m
135-
issues-exit-code: 1
136-
tests: false
137-
138-
# output configuration options
139-
output:
140-
formats:
141-
- format: 'colored-line-number'
142-
print-issued-lines: true
143-
print-linter-name: true
144-
145-
issues:
146-
exclude-rules:
147-
- text: 'G115' # TODO: Either we should fix the issues or nuke the linter if it's bad
148-
linters:
149-
- gosec
150-
# we aren't calling unknown URL
151-
- text: 'G107' # G107: Url provided to HTTP request as taint input
152-
linters:
153-
- gosec
154-
# as a web server that's expected to handle any template, this is totally in the hands of the user.
155-
- text: 'G203' # G203: Use of unescaped data in HTML templates
156-
linters:
157-
- gosec
158-
# we're shelling out to known commands, not relying on user-defined input.
159-
- text: 'G204' # G204: Audit use of command execution
160-
linters:
161-
- gosec
162-
# the choice of weakrand is deliberate, hence the named import "weakrand"
163-
- path: modules/caddyhttp/reverseproxy/selectionpolicies.go
164-
text: 'G404' # G404: Insecure random number source (rand)
165-
linters:
166-
- gosec
167-
- path: modules/caddyhttp/reverseproxy/streaming.go
168-
text: 'G404' # G404: Insecure random number source (rand)
169-
linters:
170-
- gosec
171-
- path: modules/logging/filters.go
172-
linters:
173-
- dupl
174-
- path: modules/caddyhttp/matchers.go
175-
linters:
176-
- dupl
177-
- path: modules/caddyhttp/vars.go
178-
linters:
179-
- dupl
180-
- path: _test\.go
181-
linters:
182-
- errcheck
44+
settings:
45+
staticcheck:
46+
checks: ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-QF1006", "-QF1008"] # default, and exclude 1 more undesired check
47+
errcheck:
48+
exclude-functions:
49+
- fmt.*
50+
- (go.uber.org/zap/zapcore.ObjectEncoder).AddObject
51+
- (go.uber.org/zap/zapcore.ObjectEncoder).AddArray
52+
exhaustive:
53+
ignore-enum-types: reflect.Kind|svc.Cmd
54+
exclusions:
55+
generated: lax
56+
presets:
57+
- comments
58+
- common-false-positives
59+
- legacy
60+
- std-error-handling
61+
rules:
62+
- linters:
63+
- gosec
64+
text: G115 # TODO: Either we should fix the issues or nuke the linter if it's bad
65+
- linters:
66+
- gosec
67+
text: G107 # we aren't calling unknown URL
68+
- linters:
69+
- gosec
70+
text: G203 # as a web server that's expected to handle any template, this is totally in the hands of the user.
71+
- linters:
72+
- gosec
73+
text: G204 # we're shelling out to known commands, not relying on user-defined input.
74+
- linters:
75+
- gosec
76+
# the choice of weakrand is deliberate, hence the named import "weakrand"
77+
path: modules/caddyhttp/reverseproxy/selectionpolicies.go
78+
text: G404
79+
- linters:
80+
- gosec
81+
path: modules/caddyhttp/reverseproxy/streaming.go
82+
text: G404
83+
- linters:
84+
- dupl
85+
path: modules/logging/filters.go
86+
- linters:
87+
- dupl
88+
path: modules/caddyhttp/matchers.go
89+
- linters:
90+
- dupl
91+
path: modules/caddyhttp/vars.go
92+
- linters:
93+
- errcheck
94+
path: _test\.go
95+
paths:
96+
- third_party$
97+
- builtin$
98+
- examples$
99+
formatters:
100+
enable:
101+
- gci
102+
- gofmt
103+
- gofumpt
104+
- goimports
105+
settings:
106+
gci:
107+
sections:
108+
- standard # Standard section: captures all standard packages.
109+
- default # Default section: contains all imports that could not be matched to another section type.
110+
- prefix(github.com/caddyserver/caddy/v2/cmd) # ensure that this is always at the top and always has a line break.
111+
- prefix(github.com/caddyserver/caddy) # Custom section: groups all imports with the specified Prefix.
112+
custom-order: true
113+
exclusions:
114+
generated: lax
115+
paths:
116+
- third_party$
117+
- builtin$
118+
- examples$

caddyconfig/caddyfile/adapter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (a Adapter) Adapt(body []byte, options map[string]any) ([]byte, []caddyconf
6868
// TODO: also perform this check on imported files
6969
func FormattingDifference(filename string, body []byte) (caddyconfig.Warning, bool) {
7070
// replace windows-style newlines to normalize comparison
71-
normalizedBody := bytes.Replace(body, []byte("\r\n"), []byte("\n"), -1)
71+
normalizedBody := bytes.ReplaceAll(body, []byte("\r\n"), []byte("\n"))
7272

7373
formatted := Format(normalizedBody)
7474
if bytes.Equal(formatted, normalizedBody) {

caddyconfig/caddyfile/formatter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func Format(input []byte) []byte {
9494
}
9595

9696
// detect whether we have the start of a heredoc
97-
if !quoted && !(heredoc != heredocClosed || heredocEscaped) &&
97+
if !quoted && (heredoc == heredocClosed && !heredocEscaped) &&
9898
space && last == '<' && ch == '<' {
9999
write(ch)
100100
heredoc = heredocOpening

caddyconfig/caddyfile/lexer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (l *lexer) next() (bool, error) {
137137
}
138138

139139
// detect whether we have the start of a heredoc
140-
if !(quoted || btQuoted) && !(inHeredoc || heredocEscaped) &&
140+
if (!quoted && !btQuoted) && (!inHeredoc && !heredocEscaped) &&
141141
len(val) > 1 && string(val[:2]) == "<<" {
142142
// a space means it's just a regular token and not a heredoc
143143
if ch == ' ' {

caddyconfig/httpcaddyfile/directives.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,12 @@ func RegisterDirectiveOrder(dir string, position Positional, standardDir string)
174174
if d != standardDir {
175175
continue
176176
}
177-
if position == Before {
177+
switch position {
178+
case Before:
178179
newOrder = append(newOrder[:i], append([]string{dir}, newOrder[i:]...)...)
179-
} else if position == After {
180+
case After:
180181
newOrder = append(newOrder[:i+1], append([]string{dir}, newOrder[i+1:]...)...)
182+
case First, Last:
181183
}
182184
break
183185
}

caddytest/caddytest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func validateTestPrerequisites(tc *Tester) error {
281281
tc.t.Cleanup(func() {
282282
os.Remove(f.Name())
283283
})
284-
if _, err := f.WriteString(fmt.Sprintf(initConfig, tc.config.AdminPort)); err != nil {
284+
if _, err := fmt.Fprintf(f, initConfig, tc.config.AdminPort); err != nil {
285285
return err
286286
}
287287

caddytest/integration/acme_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ import (
1212
"strings"
1313
"testing"
1414

15-
"github.com/caddyserver/caddy/v2"
16-
"github.com/caddyserver/caddy/v2/caddytest"
1715
"github.com/mholt/acmez/v3"
1816
"github.com/mholt/acmez/v3/acme"
1917
smallstepacme "github.com/smallstep/certificates/acme"
2018
"go.uber.org/zap"
2119
"go.uber.org/zap/exp/zapslog"
20+
21+
"github.com/caddyserver/caddy/v2"
22+
"github.com/caddyserver/caddy/v2/caddytest"
2223
)
2324

2425
const acmeChallengePort = 9081

caddytest/integration/acmeserver_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import (
99
"strings"
1010
"testing"
1111

12-
"github.com/caddyserver/caddy/v2/caddytest"
1312
"github.com/mholt/acmez/v3"
1413
"github.com/mholt/acmez/v3/acme"
1514
"go.uber.org/zap"
1615
"go.uber.org/zap/exp/zapslog"
16+
17+
"github.com/caddyserver/caddy/v2/caddytest"
1718
)
1819

1920
func TestACMEServerDirectory(t *testing.T) {

caddytest/integration/caddyfile_adapt_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"testing"
1111

1212
"github.com/caddyserver/caddy/v2/caddytest"
13-
1413
_ "github.com/caddyserver/caddy/v2/internal/testmocks"
1514
)
1615

caddytest/integration/caddyfile_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,6 @@ func TestReplaceWithReplacementPlaceholder(t *testing.T) {
615615
respond "{query}"`, "caddyfile")
616616

617617
tester.AssertGetResponse("http://localhost:9080/endpoint?placeholder=baz&foo=bar", 200, "foo=baz&placeholder=baz")
618-
619618
}
620619

621620
func TestReplaceWithKeyPlaceholder(t *testing.T) {

caddytest/integration/mockdns_test.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package integration
33
import (
44
"context"
55

6-
"github.com/caddyserver/caddy/v2"
7-
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
86
"github.com/caddyserver/certmagic"
97
"github.com/libdns/libdns"
8+
9+
"github.com/caddyserver/caddy/v2"
10+
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
1011
)
1112

1213
func init() {
@@ -55,7 +56,9 @@ func (MockDNSProvider) SetRecords(ctx context.Context, zone string, recs []libdn
5556
}
5657

5758
// Interface guard
58-
var _ caddyfile.Unmarshaler = (*MockDNSProvider)(nil)
59-
var _ certmagic.DNSProvider = (*MockDNSProvider)(nil)
60-
var _ caddy.Provisioner = (*MockDNSProvider)(nil)
61-
var _ caddy.Module = (*MockDNSProvider)(nil)
59+
var (
60+
_ caddyfile.Unmarshaler = (*MockDNSProvider)(nil)
61+
_ certmagic.DNSProvider = (*MockDNSProvider)(nil)
62+
_ caddy.Provisioner = (*MockDNSProvider)(nil)
63+
_ caddy.Module = (*MockDNSProvider)(nil)
64+
)

0 commit comments

Comments
 (0)