Skip to content

Commit be1dcb5

Browse files
authored
ci: upgrade golangci-lint to v2 (#4967)
1 parent 966d7fa commit be1dcb5

File tree

7 files changed

+90
-95
lines changed

7 files changed

+90
-95
lines changed

.golangci.yaml

Lines changed: 78 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
version: "2"
12
run:
23
timeout: 10m
3-
44
linters:
5-
disable-all: true
5+
default: none
66
enable:
77
- containedctx
88
#- contextcheck
@@ -12,14 +12,11 @@ linters:
1212
#- errname
1313
- errorlint
1414
#- gochecknoinits
15-
- gci
1615
#- goconst
1716
- gocritic
1817
#- gocyclo
1918
#- godot
20-
- gofumpt
2119
- gosec
22-
- gosimple
2320
- govet
2421
- ineffassign
2522
#- lll
@@ -28,88 +25,86 @@ linters:
2825
- nolintlint
2926
- prealloc
3027
- staticcheck
31-
- stylecheck
32-
- tenv
3328
- thelper
3429
#- tparallel
35-
- typecheck
3630
- unconvert
3731
- unparam
3832
- unused
33+
- usetesting
3934
- whitespace
40-
41-
linters-settings:
42-
depguard:
35+
settings:
36+
depguard:
37+
rules:
38+
prevent_kubernetes_dependency:
39+
list-mode: lax # allow unless explicitly denied
40+
deny:
41+
- pkg: k8s.io/kubernetes
42+
desc: do not use k8s.io/kubernetes directly
43+
errcheck:
44+
exclude-functions:
45+
- encoding/json.Marshal
46+
- encoding/json.MarshalIndent
47+
errchkjson:
48+
check-error-free-encoding: true
49+
gocritic:
50+
disabled-checks:
51+
- appendAssign
52+
- appendCombine
53+
- commentedOutCode
54+
- equalFold
55+
- exposedSyncMutex
56+
- httpNoBody
57+
- hugeParam
58+
- ifElseChain
59+
- importShadow
60+
- methodExprCall
61+
- nestingReduce
62+
- preferStringWriter
63+
- rangeValCopy
64+
- singleCaseSwitch
65+
- stringConcatSimplify
66+
- unlabelStmt
67+
- unnamedResult
68+
- whyNoLint
69+
enabled-tags:
70+
- diagnostic
71+
- experimental
72+
- opinionated
73+
- performance
74+
- style
75+
gosec:
76+
excludes:
77+
- G110
78+
- G115
79+
- G204
80+
- G306
81+
lll:
82+
line-length: 150
83+
usetesting:
84+
context-background: false
85+
context-todo: false
86+
exclusions:
87+
presets:
88+
- common-false-positives
89+
- legacy
90+
- std-error-handling
4391
rules:
44-
prevent_kubernetes_dependency:
45-
list-mode: lax # allow unless explicitly denied
46-
deny:
47-
- pkg: k8s.io/kubernetes
48-
desc: "do not use k8s.io/kubernetes directly"
49-
errcheck:
50-
exclude-functions:
51-
- encoding/json.Marshal
52-
- encoding/json.MarshalIndent
53-
errchkjson:
54-
check-error-free-encoding: true
55-
gci:
56-
sections:
57-
- Standard
58-
- Default
59-
- Prefix(github.com/weaveworks)
60-
- Prefix(github.com/weaveworks/weave-gitops)
61-
gocritic:
62-
disabled-checks:
63-
- appendAssign
64-
- appendCombine
65-
- commentedOutCode
66-
- equalFold
67-
- exposedSyncMutex
68-
- httpNoBody
69-
- hugeParam
70-
- ifElseChain
71-
- importShadow
72-
- methodExprCall
73-
- nestingReduce
74-
- preferStringWriter
75-
- rangeValCopy
76-
- singleCaseSwitch
77-
- stringConcatSimplify
78-
- unlabelStmt
79-
- unnamedResult
80-
- whyNoLint
81-
enabled-tags:
82-
- diagnostic
83-
- experimental
84-
- opinionated
85-
- performance
86-
- style
87-
gofumpt:
88-
extra-rules: true
89-
gosec:
90-
excludes:
91-
- G110
92-
- G115
93-
- G204
94-
- G306
95-
lll:
96-
line-length: 150
97-
98-
issues:
99-
exclude-dirs:
100-
- tilt_modules
101-
exclude-rules:
102-
# ignore errcheck for code under a /test folder
103-
- path: "test/*"
104-
linters:
105-
- errcheck
106-
# ignore errcheck for flags.Parse (it is expected that we flag.ExitOnError)
107-
# ignore response.WriteError as it always returns the err it was passed
108-
- source: "flags.Parse|response.WriteError"
109-
linters:
110-
- errcheck
111-
112-
output:
113-
formats:
114-
- format: colored-line-number
115-
path: stdout
92+
- linters:
93+
- errcheck
94+
path: test/*
95+
- linters:
96+
- errcheck
97+
source: flags.Parse|response.WriteError
98+
formatters:
99+
enable:
100+
- gci
101+
- gofumpt
102+
settings:
103+
gci:
104+
sections:
105+
- Standard
106+
- Default
107+
- Prefix(github.com/weaveworks)
108+
- Prefix(github.com/weaveworks/weave-gitops)
109+
gofumpt:
110+
extra-rules: true

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ endif
232232

233233
## Tool Binaries
234234

235-
GOLANGCI_LINT_VERSION ?= v1.63.4
235+
GOLANGCI_LINT_VERSION ?= v2.1.6
236236
PROTOLINT_VERSION ?= v0.52.0
237237

238238
LOCALBIN ?= $(shell pwd)/bin
@@ -242,7 +242,7 @@ $(LOCALBIN):
242242
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
243243
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
244244
$(GOLANGCI_LINT):
245-
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}
245+
GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}
246246

247247
PROTOLINT = $(LOCALBIN)/protolint
248248
protolint: $(PROTOLINT) ## Download protolint locally if necessary.

core/server/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (cs *coreServer) ListEvents(ctx context.Context, msg *pb.ListEventsRequest)
6969
events = append(events, &pb.Event{
7070
Type: e.Type,
7171
Component: e.Source.Component,
72-
Name: e.ObjectMeta.Name,
72+
Name: e.Name,
7373
Reason: e.Reason,
7474
Message: e.Message,
7575
Timestamp: e.LastTimestamp.Format(time.RFC3339),

pkg/run/watch/forward_port.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ func ParsePortForwardSpec(spec string) (*PortForwardSpec, error) {
5151
return nil, fmt.Errorf("invalid port forward spec: %s", spec)
5252
}
5353

54-
if kv[0] == "port" {
54+
switch kv[0] {
55+
case "port":
5556
// split into port and host port
5657
portAndHostPort := strings.Split(kv[1], ":")
5758
specMap.HostPort = portAndHostPort[0]
5859
specMap.ContainerPort = portAndHostPort[1]
59-
} else if kv[0] == "resource" {
60+
case "resource":
6061
// specMap["resource"] = kv[1]
6162
// split kv[1] into kind and name
6263
kindAndName := strings.Split(kv[1], "/")
@@ -65,9 +66,9 @@ func ParsePortForwardSpec(spec string) (*PortForwardSpec, error) {
6566
}
6667
specMap.Kind = generalizeKind(kindAndName[0])
6768
specMap.Name = kindAndName[1]
68-
} else if kv[0] == "namespace" {
69+
case "namespace":
6970
specMap.Namespace = kv[1]
70-
} else {
71+
default:
7172
specMap.Map[kv[0]] = kv[1]
7273
}
7374
}

pkg/s3/auth_middleware.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ func getCanonicalHeaders(req http.Request, signedHeaders string) string {
151151
buf.WriteString(k)
152152
buf.WriteByte(':')
153153

154-
switch {
155-
case k == "host":
154+
switch k {
155+
case "host":
156156
buf.WriteString(getHostAddr(&req))
157157
buf.WriteByte('\n')
158158
default:

pkg/services/auth/jwt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (i *internalJWTClient) GenerateJWT(expirationTime time.Duration, providerNa
5656
// It is possible for the GitLab backend to specify an `expires_in` of 0.
5757
// Edit the `Expire access tokens` setting to enable/disable expiring tokens.
5858
// Gitlab defaults to 2 hour expiration, so replicate it here I guess?
59-
claims.RegisteredClaims.ExpiresAt = jwt.NewNumericDate(time.Now().Add(2 * time.Hour))
59+
claims.ExpiresAt = jwt.NewNumericDate(time.Now().Add(2 * time.Hour))
6060
}
6161

6262
token := jwt.NewWithClaims(jwt.SigningMethodHS512, claims)

pkg/sourceignore/sourceignore_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ func TestReadPatterns(t *testing.T) {
6060
}
6161

6262
func TestReadIgnoreFile(t *testing.T) {
63-
f, err := os.CreateTemp("", IgnoreFilename)
63+
f, err := os.CreateTemp(t.TempDir(), IgnoreFilename)
6464
if err != nil {
6565
t.Fatal(err)
6666
}
67-
defer os.Remove(f.Name())
6867
if _, err = f.Write([]byte(`# .sourceignore
6968
ignore-this.txt`)); err != nil {
7069
t.Fatal(err)

0 commit comments

Comments
 (0)