Skip to content

Commit 0618553

Browse files
jorbaumchombium
authored andcommitted
Upgrade to golangci-lint v2 for improved linting
Noteworthy changes in golangci-lint v2: * New config format (migrated with `migrate` command) * Default timeout is now 0 instead of 1 minute. Also fixes issues reported by golangci-lint v2: * Same error string capitalization. Details: * Also changed two asserts in a test * Also removed "Error:" prefix * Prefer embedded field * Lift `break` into loop condition * Prefer tagged switch in some test files
1 parent b45172a commit 0618553

File tree

15 files changed

+56
-37
lines changed

15 files changed

+56
-37
lines changed

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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
version: "2"
2+
13
run:
24
# Timeout for analysis, e.g. 30s, 5m.
35
# Default: 1m
@@ -11,9 +13,28 @@ linters:
1113
- gocyclo
1214
# Inspects source code for security problems.
1315
- gosec
16+
exclusions:
17+
generated: lax
18+
presets:
19+
- comments
20+
- common-false-positives
21+
- legacy
22+
- std-error-handling
23+
paths:
24+
- third_party$
25+
- builtin$
26+
- examples$
1427

1528
issues:
1629
# Disable max issues per linter.
1730
max-issues-per-linter: 0
1831
# Disable max same issues.
1932
max-same-issues: 0
33+
34+
formatters:
35+
exclusions:
36+
generated: lax
37+
paths:
38+
- third_party$
39+
- builtin$
40+
- examples$

src/integration_tests/fakes/doppler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"code.cloudfoundry.org/loggregator-release/src/testservers"
1010
"google.golang.org/grpc"
1111

12-
. "github.com/onsi/gomega"
12+
. "github.com/onsi/gomega" //nolint:staticcheck
1313
)
1414

1515
func DopplerEgressV1Client(addr string) (func(), plumbing.DopplerClient) {

src/integration_tests/router/router_suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ func primePumpV2(ingressClient loggregator_v2.Ingress_SenderClient, subscribeCli
171171
Expect(err).ToNot(HaveOccurred())
172172
}
173173

174-
var ErrorMissingOrigin = errors.New("Event not emitted due to missing origin information")
175-
var ErrorUnknownEventType = errors.New("Cannot create envelope for unknown event type")
174+
var ErrorMissingOrigin = errors.New("event not emitted due to missing origin information")
175+
var ErrorUnknownEventType = errors.New("cannot create envelope for unknown event type")
176176

177177
func Wrap(event events.Event, origin string) (*events.Envelope, error) {
178178
if origin == "" {

src/integration_tests/trafficcontroller/fake_uaa_server_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ func (h *FakeUaaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
2222

2323
token := r.FormValue("token")
2424

25-
if token == "iAmAnAdmin" {
25+
switch token {
26+
case "iAmAnAdmin":
2627
authData := map[string]interface{}{
2728
"scope": []string{
2829
"doppler.firehose",
@@ -31,7 +32,7 @@ func (h *FakeUaaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
3132

3233
marshaled, _ := json.Marshal(authData)
3334
_, _ = w.Write(marshaled)
34-
} else if token == "iAmNotAnAdmin" {
35+
case "iAmNotAnAdmin":
3536
authData := map[string]interface{}{
3637
"scope": []string{
3738
"uaa.not-admin",
@@ -40,13 +41,13 @@ func (h *FakeUaaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
4041

4142
marshaled, _ := json.Marshal(authData)
4243
_, _ = w.Write(marshaled)
43-
} else if token == "expiredToken" {
44+
case "expiredToken":
4445
w.WriteHeader(http.StatusBadRequest)
4546
_, _ = w.Write([]byte("{\"error\":\"invalid_token\",\"error_description\":\"Token has expired\"}"))
46-
} else if token == "invalidToken" {
47+
case "invalidToken":
4748
w.WriteHeader(http.StatusBadRequest)
4849
_, _ = w.Write([]byte("{\"invalidToken\":\"invalid_token\",\"error_description\":\"Invalid token (could not decode): invalidToken\"}"))
49-
} else {
50+
default:
5051
w.WriteHeader(http.StatusInternalServerError)
5152
}
5253

src/metricemitter/counter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewCounter(name, sourceID string, opts ...MetricOption) *Counter {
3535
name: name,
3636
sourceID: sourceID,
3737
}
38-
m.Tagged.tags = make(map[string]*loggregator_v2.Value)
38+
m.tags = make(map[string]*loggregator_v2.Value)
3939

4040
for _, opt := range opts {
4141
opt(m.Tagged)

src/metricemitter/gauge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewGauge(name, unit, sourceID string, opts ...MetricOption) *Gauge {
2727
unit: unit,
2828
sourceID: sourceID,
2929
}
30-
m.Tagged.tags = make(map[string]*loggregator_v2.Value)
30+
m.tags = make(map[string]*loggregator_v2.Value)
3131

3232
for _, opt := range opts {
3333
opt(m.Tagged)

src/router/internal/server/v1/doppler_server.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,7 @@ func (m *DopplerServer) sendData(req *plumbing.SubscriptionRequest, sender sende
104104
var done int64
105105
go m.monitorContext(sender.Context(), &done)
106106

107-
for {
108-
if atomic.LoadInt64(&done) > 0 {
109-
break
110-
}
111-
107+
for atomic.LoadInt64(&done) <= 0 {
112108
data, ok := d.TryNext()
113109
if !ok {
114110
time.Sleep(10 * time.Millisecond)

src/router/internal/sinks/message_router_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ var _ = Describe("Message Router", func() {
5656
})
5757
})
5858

59-
var errorMissingOrigin = errors.New("Event not emitted due to missing origin information")
60-
var errorUnknownEventType = errors.New("Cannot create envelope for unknown event type")
59+
var errorMissingOrigin = errors.New("event not emitted due to missing origin information")
60+
var errorUnknownEventType = errors.New("cannot create envelope for unknown event type")
6161

6262
func wrap(event events.Event, origin string) (*events.Envelope, error) {
6363
if origin == "" {

src/testservers/router.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
envstruct "code.cloudfoundry.org/go-envstruct"
99
"code.cloudfoundry.org/loggregator-release/src/router/app"
1010

11-
. "github.com/onsi/ginkgo/v2"
12-
. "github.com/onsi/gomega"
11+
. "github.com/onsi/ginkgo/v2" //nolint:staticcheck
12+
. "github.com/onsi/gomega" //nolint:staticcheck
1313
"github.com/onsi/gomega/gexec"
1414
)
1515

0 commit comments

Comments
 (0)