Skip to content

Commit 2665bbf

Browse files
jorbaumchombium
authored andcommitted
Upgrade to golangci-lint v2 for improved linting
Also fixes issues reported by golangci-lint v2: * Change `Replace` to `ReplaceAll` where sensible * Omit an embedded field * `ingress/v2` had been imported twice * Nicer casing in logs Noteworthy changes in golangci-lint v2: * New config format (migrated with `migrate` command) * Default timeout is now 0 instead of 1 minute.
1 parent 191cd06 commit 2665bbf

13 files changed

Lines changed: 45 additions & 27 deletions

File tree

scripts/subtests/lint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set +e
99
golangci_lint_executable=$(which golangci-lint)
1010
set -e
1111
if [ -z "${golangci_lint_executable}" ] || [ ! -x "${golangci_lint_executable}" ]; then
12-
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
12+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
1313
fi
1414

1515
pushd "${SCRIPT_DIR}/../../src" > /dev/null

src/.golangci.yml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
version: "2"
12
run:
2-
# Timeout for analysis, e.g. 30s, 5m.
3-
# Default: 1m
3+
# Timeout full work, e.g. 30s, 5m.
4+
# Default: none
45
timeout: 5m
5-
66
linters:
77
enable:
88
# Checks for non-ASCII identifiers
@@ -11,15 +11,31 @@ linters:
1111
- gocyclo
1212
# Inspects source code for security problems.
1313
- gosec
14-
14+
exclusions:
15+
generated: lax
16+
presets:
17+
- comments
18+
- common-false-positives
19+
- legacy
20+
- std-error-handling
21+
rules:
22+
# Exclude some linters from running on helheim generated file.
23+
- linters:
24+
- unused
25+
path: pkg/egress/v2/helheim_test\.go
26+
paths:
27+
- third_party$
28+
- builtin$
29+
- examples$
1530
issues:
1631
# Disable max issues per linter.
1732
max-issues-per-linter: 0
1833
# Disable max same issues.
1934
max-same-issues: 0
20-
21-
exclude-rules:
22-
# Exclude some linters from running on helheim generated file.
23-
- path: pkg/egress/v2/helheim_test\.go
24-
linters:
25-
- unused
35+
formatters:
36+
exclusions:
37+
generated: lax
38+
paths:
39+
- third_party$
40+
- builtin$
41+
- examples$

src/cmd/loggregator-agent/app/app_v1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (a *AppV1) Start() {
8484
a.metricClient,
8585
)
8686
if err != nil {
87-
log.Panic(fmt.Errorf("Failed to listen on %s: %s", agentAddress, err))
87+
log.Panic(fmt.Errorf("failed to listen on %s: %s", agentAddress, err))
8888
}
8989

9090
log.Printf("agent v1 API started on addr %s", agentAddress)

src/cmd/loggregator-agent/app/app_v2.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/diodes"
1919
egress "code.cloudfoundry.org/loggregator-agent-release/src/pkg/egress/v2"
2020
ingress "code.cloudfoundry.org/loggregator-agent-release/src/pkg/ingress/v2"
21-
v2 "code.cloudfoundry.org/loggregator-agent-release/src/pkg/ingress/v2"
2221
"code.cloudfoundry.org/loggregator-agent-release/src/pkg/plumbing"
2322
"google.golang.org/grpc"
2423
"google.golang.org/grpc/credentials"
@@ -137,7 +136,7 @@ func (a *AppV2) Start() {
137136
var es envelopeSetter
138137
es = envelopeBuffer
139138
if a.config.LogsDisabled {
140-
es = v2.NewFilteringSetter(envelopeBuffer)
139+
es = ingress.NewFilteringSetter(envelopeBuffer)
141140
}
142141

143142
rx := ingress.NewReceiver(es, ingressMetric, originMappings)

src/cmd/loggregator-agent/app/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func LoadConfig() (*Config, error) {
6666
if err != nil {
6767
return nil, err
6868
}
69-
cfg.RouterAddrWithAZ = strings.Replace(cfg.RouterAddrWithAZ, "@", "-", -1)
69+
cfg.RouterAddrWithAZ = strings.ReplaceAll(cfg.RouterAddrWithAZ, "@", "-")
7070

7171
return &cfg, nil
7272
}

src/cmd/syslog-agent/app/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func convertCipherStringToInt(cipherStrs []string, cipherMap map[string]uint16)
140140
for key := range cipherMap {
141141
supportedCipherSuites = append(supportedCipherSuites, key)
142142
}
143-
return nil, fmt.Errorf("Invalid cipher string configuration: %s, please choose from %v", cipher, supportedCipherSuites)
143+
return nil, fmt.Errorf("invalid cipher string configuration: %s, please choose from %v", cipher, supportedCipherSuites)
144144
}
145145
}
146146

src/cmd/syslog-agent/app/syslog_agent_mtls_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ func (f *fakeBindingCache) startTLS(testCerts *testhelper.TestCerts) {
285285
Expect(err).ToNot(HaveOccurred())
286286

287287
f.Server = httptest.NewUnstartedServer(f)
288-
f.Server.TLS = tlsConfig
289-
f.Server.StartTLS()
288+
f.TLS = tlsConfig
289+
f.StartTLS()
290290
}
291291

292292
func (f *fakeBindingCache) ServeHTTP(w http.ResponseWriter, r *http.Request) {

src/cmd/syslog-binding-cache/app/syslog_binding_cache_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ func (f *fakeCC) startTLS(testCerts *testhelper.TestCerts) {
289289
Expect(err).ToNot(HaveOccurred())
290290

291291
f.Server = httptest.NewUnstartedServer(f)
292-
f.Server.TLS = tlsConfig
293-
f.Server.StartTLS()
292+
f.TLS = tlsConfig
293+
f.StartTLS()
294294
}
295295

296296
func (f *fakeCC) ServeHTTP(w http.ResponseWriter, r *http.Request) {

src/internal/testservers/agent.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import (
1111
"code.cloudfoundry.org/loggregator-agent-release/src/cmd/loggregator-agent/app"
1212
"code.cloudfoundry.org/loggregator-agent-release/src/internal/testhelper"
1313

14+
// . imports are common usage for ginkgo
15+
//nolint:staticcheck
1416
. "github.com/onsi/ginkgo/v2"
17+
//nolint:staticcheck
1518
. "github.com/onsi/gomega"
1619
"github.com/onsi/gomega/gexec"
1720
)

src/pkg/egress/syslog/https.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ func (*HTTPSWriter) sanitizeError(u *url.URL, err error) error {
9191
}
9292

9393
if user := u.User.Username(); user != "" {
94-
err = errors.New(strings.Replace(err.Error(), user, "<REDACTED>", -1))
94+
err = errors.New(strings.ReplaceAll(err.Error(), user, "<REDACTED>"))
9595
}
9696

9797
if p, ok := u.User.Password(); ok {
98-
err = errors.New(strings.Replace(err.Error(), p, "<REDACTED>", -1))
98+
err = errors.New(strings.ReplaceAll(err.Error(), p, "<REDACTED>"))
9999
}
100100
return err
101101
}

0 commit comments

Comments
 (0)