mirror of
https://github.com/caddyserver/caddy.git
synced 2025-05-31 04:05:46 -04:00
chore: upgrade .golangci.yml and workflow to v2
run `golangci-lint fmt` Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com>
This commit is contained in:
parent
7672b7848f
commit
fb467eb9a5
2
.github/workflows/lint.yml
vendored
2
.github/workflows/lint.yml
vendored
@ -51,7 +51,7 @@ jobs:
|
|||||||
check-latest: true
|
check-latest: true
|
||||||
|
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v6
|
uses: golangci/golangci-lint-action@v7
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
|
|
||||||
|
235
.golangci.yml
235
.golangci.yml
@ -1,27 +1,15 @@
|
|||||||
linters-settings:
|
version: "2"
|
||||||
errcheck:
|
run:
|
||||||
exclude-functions:
|
issues-exit-code: 1
|
||||||
- fmt.*
|
tests: false
|
||||||
- (go.uber.org/zap/zapcore.ObjectEncoder).AddObject
|
output:
|
||||||
- (go.uber.org/zap/zapcore.ObjectEncoder).AddArray
|
formats:
|
||||||
gci:
|
text:
|
||||||
sections:
|
path: stdout
|
||||||
- standard # Standard section: captures all standard packages.
|
print-linter-name: true
|
||||||
- default # Default section: contains all imports that could not be matched to another section type.
|
print-issued-lines: true
|
||||||
- prefix(github.com/caddyserver/caddy/v2/cmd) # ensure that this is always at the top and always has a line break.
|
|
||||||
- prefix(github.com/caddyserver/caddy) # Custom section: groups all imports with the specified Prefix.
|
|
||||||
# Skip generated files.
|
|
||||||
# Default: true
|
|
||||||
skip-generated: true
|
|
||||||
# Enable custom order of sections.
|
|
||||||
# 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:
|
linters:
|
||||||
disable-all: true
|
default: none
|
||||||
enable:
|
enable:
|
||||||
- asasalint
|
- asasalint
|
||||||
- asciicheck
|
- asciicheck
|
||||||
@ -35,148 +23,93 @@ linters:
|
|||||||
- errcheck
|
- errcheck
|
||||||
- errname
|
- errname
|
||||||
- exhaustive
|
- exhaustive
|
||||||
- gci
|
|
||||||
- gofmt
|
|
||||||
- goimports
|
|
||||||
- gofumpt
|
|
||||||
- gosec
|
- gosec
|
||||||
- gosimple
|
|
||||||
- govet
|
- govet
|
||||||
- ineffassign
|
|
||||||
- importas
|
- importas
|
||||||
|
- ineffassign
|
||||||
- misspell
|
- misspell
|
||||||
- prealloc
|
- prealloc
|
||||||
- promlinter
|
- promlinter
|
||||||
- sloglint
|
- sloglint
|
||||||
- sqlclosecheck
|
- sqlclosecheck
|
||||||
- staticcheck
|
- staticcheck
|
||||||
- tenv
|
|
||||||
- testableexamples
|
- testableexamples
|
||||||
- testifylint
|
- testifylint
|
||||||
- tparallel
|
- tparallel
|
||||||
- typecheck
|
|
||||||
- unconvert
|
- unconvert
|
||||||
- unused
|
- unused
|
||||||
- wastedassign
|
- wastedassign
|
||||||
- whitespace
|
- whitespace
|
||||||
- zerologlint
|
- zerologlint
|
||||||
# these are implicitly disabled:
|
settings:
|
||||||
# - containedctx
|
errcheck:
|
||||||
# - contextcheck
|
exclude-functions:
|
||||||
# - cyclop
|
- fmt.*
|
||||||
# - depguard
|
- (go.uber.org/zap/zapcore.ObjectEncoder).AddObject
|
||||||
# - errchkjson
|
- (go.uber.org/zap/zapcore.ObjectEncoder).AddArray
|
||||||
# - errorlint
|
exhaustive:
|
||||||
# - exhaustruct
|
ignore-enum-types: reflect.Kind|svc.Cmd
|
||||||
# - execinquery
|
exclusions:
|
||||||
# - exhaustruct
|
generated: lax
|
||||||
# - forbidigo
|
presets:
|
||||||
# - forcetypeassert
|
- comments
|
||||||
# - funlen
|
- common-false-positives
|
||||||
# - ginkgolinter
|
- legacy
|
||||||
# - gocheckcompilerdirectives
|
- std-error-handling
|
||||||
# - gochecknoglobals
|
rules:
|
||||||
# - gochecknoinits
|
- linters:
|
||||||
# - gochecksumtype
|
- gosec
|
||||||
# - gocognit
|
text: G115
|
||||||
# - goconst
|
- linters:
|
||||||
# - gocritic
|
- gosec
|
||||||
# - gocyclo
|
text: G107
|
||||||
# - godot
|
- linters:
|
||||||
# - godox
|
- gosec
|
||||||
# - goerr113
|
text: G203
|
||||||
# - goheader
|
- linters:
|
||||||
# - gomnd
|
- gosec
|
||||||
# - gomoddirectives
|
text: G204
|
||||||
# - gomodguard
|
- linters:
|
||||||
# - goprintffuncname
|
- gosec
|
||||||
# - gosmopolitan
|
path: modules/caddyhttp/reverseproxy/selectionpolicies.go
|
||||||
# - grouper
|
text: G404
|
||||||
# - inamedparam
|
- linters:
|
||||||
# - interfacebloat
|
- gosec
|
||||||
# - ireturn
|
path: modules/caddyhttp/reverseproxy/streaming.go
|
||||||
# - lll
|
text: G404
|
||||||
# - loggercheck
|
- linters:
|
||||||
# - maintidx
|
- dupl
|
||||||
# - makezero
|
path: modules/logging/filters.go
|
||||||
# - mirror
|
- linters:
|
||||||
# - musttag
|
- dupl
|
||||||
# - nakedret
|
path: modules/caddyhttp/matchers.go
|
||||||
# - nestif
|
- linters:
|
||||||
# - nilerr
|
- dupl
|
||||||
# - nilnil
|
path: modules/caddyhttp/vars.go
|
||||||
# - nlreturn
|
- linters:
|
||||||
# - noctx
|
- errcheck
|
||||||
# - nolintlint
|
path: _test\.go
|
||||||
# - nonamedreturns
|
paths:
|
||||||
# - nosprintfhostport
|
- third_party$
|
||||||
# - paralleltest
|
- builtin$
|
||||||
# - perfsprint
|
- examples$
|
||||||
# - predeclared
|
formatters:
|
||||||
# - protogetter
|
enable:
|
||||||
# - reassign
|
- gci
|
||||||
# - revive
|
- gofmt
|
||||||
# - rowserrcheck
|
- gofumpt
|
||||||
# - stylecheck
|
- goimports
|
||||||
# - tagalign
|
settings:
|
||||||
# - tagliatelle
|
gci:
|
||||||
# - testpackage
|
sections:
|
||||||
# - thelper
|
- standard
|
||||||
# - unparam
|
- default
|
||||||
# - usestdlibvars
|
- prefix(github.com/caddyserver/caddy/v2/cmd)
|
||||||
# - varnamelen
|
- prefix(github.com/caddyserver/caddy)
|
||||||
# - wrapcheck
|
custom-order: true
|
||||||
# - wsl
|
exclusions:
|
||||||
|
generated: lax
|
||||||
run:
|
paths:
|
||||||
# default concurrency is a available CPU number.
|
- third_party$
|
||||||
# concurrency: 4 # explicitly omit this value to fully utilize available resources.
|
- builtin$
|
||||||
timeout: 5m
|
- examples$
|
||||||
issues-exit-code: 1
|
|
||||||
tests: false
|
|
||||||
|
|
||||||
# output configuration options
|
|
||||||
output:
|
|
||||||
formats:
|
|
||||||
- format: 'colored-line-number'
|
|
||||||
print-issued-lines: true
|
|
||||||
print-linter-name: true
|
|
||||||
|
|
||||||
issues:
|
|
||||||
exclude-rules:
|
|
||||||
- text: 'G115' # TODO: Either we should fix the issues or nuke the linter if it's bad
|
|
||||||
linters:
|
|
||||||
- gosec
|
|
||||||
# we aren't calling unknown URL
|
|
||||||
- text: 'G107' # G107: Url provided to HTTP request as taint input
|
|
||||||
linters:
|
|
||||||
- gosec
|
|
||||||
# as a web server that's expected to handle any template, this is totally in the hands of the user.
|
|
||||||
- text: 'G203' # G203: Use of unescaped data in HTML templates
|
|
||||||
linters:
|
|
||||||
- gosec
|
|
||||||
# we're shelling out to known commands, not relying on user-defined input.
|
|
||||||
- text: 'G204' # G204: Audit use of command execution
|
|
||||||
linters:
|
|
||||||
- gosec
|
|
||||||
# the choice of weakrand is deliberate, hence the named import "weakrand"
|
|
||||||
- path: modules/caddyhttp/reverseproxy/selectionpolicies.go
|
|
||||||
text: 'G404' # G404: Insecure random number source (rand)
|
|
||||||
linters:
|
|
||||||
- gosec
|
|
||||||
- path: modules/caddyhttp/reverseproxy/streaming.go
|
|
||||||
text: 'G404' # G404: Insecure random number source (rand)
|
|
||||||
linters:
|
|
||||||
- gosec
|
|
||||||
- path: modules/logging/filters.go
|
|
||||||
linters:
|
|
||||||
- dupl
|
|
||||||
- path: modules/caddyhttp/matchers.go
|
|
||||||
linters:
|
|
||||||
- dupl
|
|
||||||
- path: modules/caddyhttp/vars.go
|
|
||||||
linters:
|
|
||||||
- dupl
|
|
||||||
- path: _test\.go
|
|
||||||
linters:
|
|
||||||
- errcheck
|
|
||||||
|
@ -12,13 +12,14 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy/v2"
|
|
||||||
"github.com/caddyserver/caddy/v2/caddytest"
|
|
||||||
"github.com/mholt/acmez/v3"
|
"github.com/mholt/acmez/v3"
|
||||||
"github.com/mholt/acmez/v3/acme"
|
"github.com/mholt/acmez/v3/acme"
|
||||||
smallstepacme "github.com/smallstep/certificates/acme"
|
smallstepacme "github.com/smallstep/certificates/acme"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"go.uber.org/zap/exp/zapslog"
|
"go.uber.org/zap/exp/zapslog"
|
||||||
|
|
||||||
|
"github.com/caddyserver/caddy/v2"
|
||||||
|
"github.com/caddyserver/caddy/v2/caddytest"
|
||||||
)
|
)
|
||||||
|
|
||||||
const acmeChallengePort = 9081
|
const acmeChallengePort = 9081
|
||||||
|
@ -9,11 +9,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy/v2/caddytest"
|
|
||||||
"github.com/mholt/acmez/v3"
|
"github.com/mholt/acmez/v3"
|
||||||
"github.com/mholt/acmez/v3/acme"
|
"github.com/mholt/acmez/v3/acme"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"go.uber.org/zap/exp/zapslog"
|
"go.uber.org/zap/exp/zapslog"
|
||||||
|
|
||||||
|
"github.com/caddyserver/caddy/v2/caddytest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestACMEServerDirectory(t *testing.T) {
|
func TestACMEServerDirectory(t *testing.T) {
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy/v2/caddytest"
|
"github.com/caddyserver/caddy/v2/caddytest"
|
||||||
|
|
||||||
_ "github.com/caddyserver/caddy/v2/internal/testmocks"
|
_ "github.com/caddyserver/caddy/v2/internal/testmocks"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -615,7 +615,6 @@ func TestReplaceWithReplacementPlaceholder(t *testing.T) {
|
|||||||
respond "{query}"`, "caddyfile")
|
respond "{query}"`, "caddyfile")
|
||||||
|
|
||||||
tester.AssertGetResponse("http://localhost:9080/endpoint?placeholder=baz&foo=bar", 200, "foo=baz&placeholder=baz")
|
tester.AssertGetResponse("http://localhost:9080/endpoint?placeholder=baz&foo=bar", 200, "foo=baz&placeholder=baz")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReplaceWithKeyPlaceholder(t *testing.T) {
|
func TestReplaceWithKeyPlaceholder(t *testing.T) {
|
||||||
|
@ -3,10 +3,11 @@ package integration
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy/v2"
|
|
||||||
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
|
|
||||||
"github.com/caddyserver/certmagic"
|
"github.com/caddyserver/certmagic"
|
||||||
"github.com/libdns/libdns"
|
"github.com/libdns/libdns"
|
||||||
|
|
||||||
|
"github.com/caddyserver/caddy/v2"
|
||||||
|
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -55,7 +56,9 @@ func (MockDNSProvider) SetRecords(ctx context.Context, zone string, recs []libdn
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Interface guard
|
// Interface guard
|
||||||
var _ caddyfile.Unmarshaler = (*MockDNSProvider)(nil)
|
var (
|
||||||
var _ certmagic.DNSProvider = (*MockDNSProvider)(nil)
|
_ caddyfile.Unmarshaler = (*MockDNSProvider)(nil)
|
||||||
var _ caddy.Provisioner = (*MockDNSProvider)(nil)
|
_ certmagic.DNSProvider = (*MockDNSProvider)(nil)
|
||||||
var _ caddy.Module = (*MockDNSProvider)(nil)
|
_ caddy.Provisioner = (*MockDNSProvider)(nil)
|
||||||
|
_ caddy.Module = (*MockDNSProvider)(nil)
|
||||||
|
)
|
||||||
|
@ -13,9 +13,10 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy/v2/caddytest"
|
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
"golang.org/x/net/http2/h2c"
|
"golang.org/x/net/http2/h2c"
|
||||||
|
|
||||||
|
"github.com/caddyserver/caddy/v2/caddytest"
|
||||||
)
|
)
|
||||||
|
|
||||||
// (see https://github.com/caddyserver/caddy/issues/3556 for use case)
|
// (see https://github.com/caddyserver/caddy/issues/3556 for use case)
|
||||||
|
@ -235,7 +235,6 @@ func Test_isCaddyfile(t *testing.T) {
|
|||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
||||||
name: "json is not caddyfile but not error",
|
name: "json is not caddyfile but not error",
|
||||||
args: args{
|
args: args{
|
||||||
configFile: "./Caddyfile.json",
|
configFile: "./Caddyfile.json",
|
||||||
@ -245,7 +244,6 @@ func Test_isCaddyfile(t *testing.T) {
|
|||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
||||||
name: "prefix of Caddyfile and ./ with any extension is Caddyfile",
|
name: "prefix of Caddyfile and ./ with any extension is Caddyfile",
|
||||||
args: args{
|
args: args{
|
||||||
configFile: "./Caddyfile.prd",
|
configFile: "./Caddyfile.prd",
|
||||||
@ -255,7 +253,6 @@ func Test_isCaddyfile(t *testing.T) {
|
|||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
||||||
name: "prefix of Caddyfile without ./ with any extension is Caddyfile",
|
name: "prefix of Caddyfile without ./ with any extension is Caddyfile",
|
||||||
args: args{
|
args: args{
|
||||||
configFile: "Caddyfile.prd",
|
configFile: "Caddyfile.prd",
|
||||||
|
@ -30,7 +30,7 @@ func TestSplitNetworkAddress(t *testing.T) {
|
|||||||
expectErr bool
|
expectErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
input: "",
|
input: "",
|
||||||
expectHost: "",
|
expectHost: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -41,7 +41,7 @@ func TestSplitNetworkAddress(t *testing.T) {
|
|||||||
input: ":", // empty host & empty port
|
input: ":", // empty host & empty port
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: "::",
|
input: "::",
|
||||||
expectHost: "::",
|
expectHost: "::",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -184,9 +184,8 @@ func TestParseNetworkAddress(t *testing.T) {
|
|||||||
expectErr bool
|
expectErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
input: "",
|
input: "",
|
||||||
expectAddr: NetworkAddress{
|
expectAddr: NetworkAddress{},
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: ":",
|
input: ":",
|
||||||
@ -311,9 +310,8 @@ func TestParseNetworkAddressWithDefaults(t *testing.T) {
|
|||||||
expectErr bool
|
expectErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
input: "",
|
input: "",
|
||||||
expectAddr: NetworkAddress{
|
expectAddr: NetworkAddress{},
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: ":",
|
input: ":",
|
||||||
|
@ -9,8 +9,9 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy/v2"
|
|
||||||
"github.com/prometheus/client_golang/prometheus/testutil"
|
"github.com/prometheus/client_golang/prometheus/testutil"
|
||||||
|
|
||||||
|
"github.com/caddyserver/caddy/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServerNameFromContext(t *testing.T) {
|
func TestServerNameFromContext(t *testing.T) {
|
||||||
|
@ -52,5 +52,4 @@ func TestResolveIpVersion(t *testing.T) {
|
|||||||
t.Errorf("resolveIpVersion(): Expected %s got %s", test.expectedIpVersion, ipVersion)
|
t.Errorf("resolveIpVersion(): Expected %s got %s", test.expectedIpVersion, ipVersion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -171,6 +171,7 @@ func BenchmarkServer_LogRequest_WithTrace(b *testing.B) {
|
|||||||
s.logRequest(accLog, req, wrec, &duration, repl, bodyReader, false)
|
s.logRequest(accLog, req, wrec, &duration, repl, bodyReader, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServer_TrustedRealClientIP_NoTrustedHeaders(t *testing.T) {
|
func TestServer_TrustedRealClientIP_NoTrustedHeaders(t *testing.T) {
|
||||||
req := httptest.NewRequest("GET", "/", nil)
|
req := httptest.NewRequest("GET", "/", nil)
|
||||||
req.RemoteAddr = "192.0.2.1:12345"
|
req.RemoteAddr = "192.0.2.1:12345"
|
||||||
|
@ -76,7 +76,6 @@ func TestSvcParamsString(t *testing.T) {
|
|||||||
// because we can't just compare string outputs
|
// because we can't just compare string outputs
|
||||||
// since map iteration is unordered
|
// since map iteration is unordered
|
||||||
for i, test := range []svcParams{
|
for i, test := range []svcParams{
|
||||||
|
|
||||||
{
|
{
|
||||||
"alpn": {"h2", "h3"},
|
"alpn": {"h2", "h3"},
|
||||||
"no-default-alpn": {},
|
"no-default-alpn": {},
|
||||||
|
@ -317,7 +317,7 @@ func TestFileModeToJSON(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "none zero",
|
name: "none zero",
|
||||||
mode: 0644,
|
mode: 0o644,
|
||||||
want: `"0644"`,
|
want: `"0644"`,
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
@ -358,7 +358,7 @@ func TestFileModeModification(t *testing.T) {
|
|||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
fpath := path.Join(dir, "test.log")
|
fpath := path.Join(dir, "test.log")
|
||||||
f_tmp, err := os.OpenFile(fpath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(0600))
|
f_tmp, err := os.OpenFile(fpath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.FileMode(0o600))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create test file: %v", err)
|
t.Fatalf("failed to create test file: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,10 @@ package logging
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"go.uber.org/zap/zapcore"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy/v2"
|
"github.com/caddyserver/caddy/v2"
|
||||||
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
|
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
|
||||||
"go.uber.org/zap/zapcore"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIPMaskSingleValue(t *testing.T) {
|
func TestIPMaskSingleValue(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user