Skip to content

Commit c891c8b

Browse files
authored
chore: upgrade golangci lint version to v2 (#114)
Signed-off-by: ashing <[email protected]>
1 parent 7548a22 commit c891c8b

File tree

27 files changed

+102
-97
lines changed

27 files changed

+102
-97
lines changed

.golangci.yml

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,14 @@
1+
version: "2"
12
run:
2-
timeout: 5m
33
allow-parallel-runners: true
4-
5-
issues:
6-
# don't skip warning about doc comments
7-
# don't exclude the default set of lint
8-
exclude-use-default: false
9-
# restore some of the defaults
10-
# (fill in the rest as needed)
11-
exclude-rules:
12-
- path: "api/*"
13-
linters:
14-
- lll
15-
- path: "internal/*"
16-
linters:
17-
- dupl
18-
- lll
194
linters:
20-
disable-all: true
5+
default: none
216
enable:
227
- dupl
238
- errcheck
24-
- exportloopref
259
- ginkgolinter
2610
- goconst
2711
- gocyclo
28-
- gofmt
29-
- goimports
30-
- gosimple
3112
- govet
3213
- ineffassign
3314
- lll
@@ -36,12 +17,38 @@ linters:
3617
- prealloc
3718
- revive
3819
- staticcheck
39-
- typecheck
4020
- unconvert
4121
- unparam
4222
- unused
43-
44-
linters-settings:
45-
revive:
23+
settings:
24+
revive:
25+
rules:
26+
- name: comment-spacings
27+
exclusions:
28+
generated: lax
4629
rules:
47-
- name: comment-spacings
30+
- linters:
31+
- lll
32+
path: api/*
33+
- linters:
34+
- dupl
35+
- lll
36+
path: internal/*
37+
- linters:
38+
- staticcheck
39+
text: "ST1001:"
40+
path: test/.*
41+
paths:
42+
- third_party$
43+
- builtin$
44+
- examples$
45+
formatters:
46+
enable:
47+
- gofmt
48+
- goimports
49+
exclusions:
50+
generated: lax
51+
paths:
52+
- third_party$
53+
- builtin$
54+
- examples$

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
285285
KUSTOMIZE_VERSION ?= v5.4.2
286286
CONTROLLER_TOOLS_VERSION ?= v0.15.0
287287
ENVTEST_VERSION ?= release-0.18
288-
GOLANGCI_LINT_VERSION ?= v1.59.1
288+
GOLANGCI_LINT_VERSION ?= v2.1.5
289289

290290
.PHONY: kustomize
291291
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
@@ -305,7 +305,7 @@ $(ENVTEST): $(LOCALBIN)
305305
.PHONY: golangci-lint
306306
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
307307
$(GOLANGCI_LINT): $(LOCALBIN)
308-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
308+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s $(GOLANGCI_LINT_VERSION)
309309

310310
gofmt: ## Apply go fmt
311311
@gofmt -w -r 'interface{} -> any' .

api/dashboard/v1/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,9 +730,9 @@ func ComposeConsumerName(namespace, name string) string {
730730
buf := bytes.NewBuffer(p)
731731

732732
// TODO If APISIX modifies the consumer name schema, we can drop this.
733-
buf.WriteString(strings.Replace(namespace, "-", "_", -1))
733+
buf.WriteString(strings.ReplaceAll(namespace, "-", "_"))
734734
buf.WriteString("_")
735-
buf.WriteString(strings.Replace(name, "-", "_", -1))
735+
buf.WriteString(strings.ReplaceAll(name, "-", "_"))
736736

737737
return buf.String()
738738
}

internal/controller/consumer_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func (r *ConsumerReconciler) checkGatewayRef(object client.Object) bool {
307307
return false
308308
}
309309
gatewayClass := &gatewayv1.GatewayClass{}
310-
if err := r.Client.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
310+
if err := r.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
311311
r.Log.Error(err, "failed to get gateway class", "gateway", gateway.GetName(), "gatewayclass", gateway.Spec.GatewayClassName)
312312
return false
313313
}

internal/controller/gateway_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ func (r *GatewayReconciler) listGatewayForGatewayClass(ctx context.Context, gate
208208
func (r *GatewayReconciler) checkGatewayClass(obj client.Object) bool {
209209
gateway := obj.(*gatewayv1.Gateway)
210210
gatewayClass := &gatewayv1.GatewayClass{}
211-
if err := r.Client.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
211+
if err := r.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil {
212212
r.Log.Error(err, "failed to get gateway class", "gateway", gateway.GetName(), "gatewayclass", gateway.Spec.GatewayClassName)
213213
return false
214214
}

internal/controller/ingress_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ func (r *IngressReconciler) getIngressClass(obj client.Object) (*networkingv1.In
209209

210210
// if it does not match, check if the ingress class is controlled by us
211211
ingressClass := networkingv1.IngressClass{}
212-
if err := r.Client.Get(context.Background(), client.ObjectKey{Name: *ingress.Spec.IngressClassName}, &ingressClass); err != nil {
212+
if err := r.Get(context.Background(), client.ObjectKey{Name: *ingress.Spec.IngressClassName}, &ingressClass); err != nil {
213213
return nil, err
214214
}
215215

internal/provider/adc/translator/consumer.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package translator
33
import (
44
"encoding/json"
55

6-
"github.com/api7/api7-ingress-controller/api/adc"
76
adctypes "github.com/api7/api7-ingress-controller/api/adc"
87
"github.com/api7/api7-ingress-controller/api/v1alpha1"
98
"github.com/api7/api7-ingress-controller/internal/provider"
@@ -22,7 +21,7 @@ func (t *Translator) TranslateConsumerV1alpha1(tctx *provider.TranslateContext,
2221
}
2322
credentials := make([]adctypes.Credential, 0, len(consumerV.Spec.Credentials))
2423
for _, credentialSpec := range consumerV.Spec.Credentials {
25-
credential := adc.Credential{}
24+
credential := adctypes.Credential{}
2625
credential.Name = credentialSpec.Name
2726
credential.Type = credentialSpec.Type
2827
if credentialSpec.SecretRef != nil {

internal/provider/adc/translator/httproute.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ func (t *Translator) fillPluginFromHTTPRequestMirrorFilter(plugins adctypes.Plug
180180
}
181181

182182
var (
183-
port int = 80
184-
ns string = namespace
183+
port = 80
184+
ns = namespace
185185
)
186186
if reqMirror.BackendRef.Port != nil {
187187
port = int(*reqMirror.BackendRef.Port)

internal/provider/adc/translator/ingress.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ func (t *Translator) TranslateIngress(tctx *provider.TranslateContext, obj *netw
171171

172172
uris := []string{path.Path}
173173
if path.PathType != nil {
174-
if *path.PathType == networkingv1.PathTypePrefix {
174+
switch *path.PathType {
175+
case networkingv1.PathTypePrefix:
175176
// As per the specification of Ingress path matching rule:
176177
// if the last element of the path is a substring of the
177178
// last element in request path, it is not a match, e.g. /foo/bar
@@ -188,7 +189,7 @@ func (t *Translator) TranslateIngress(tctx *provider.TranslateContext, obj *netw
188189
prefix += "/*"
189190
}
190191
uris = append(uris, prefix)
191-
} else if *path.PathType == networkingv1.PathTypeImplementationSpecific {
192+
case networkingv1.PathTypeImplementationSpecific:
192193
uris = []string{"/*"}
193194
}
194195
}

internal/provider/adc/translator/policies.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package translator
22

33
import (
4-
"github.com/api7/api7-ingress-controller/api/adc"
4+
adctypes "github.com/api7/api7-ingress-controller/api/adc"
55
"github.com/api7/api7-ingress-controller/api/v1alpha1"
66
"k8s.io/apimachinery/pkg/types"
77
"k8s.io/utils/ptr"
88
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
9-
10-
adctypes "github.com/api7/api7-ingress-controller/api/adc"
119
)
1210

1311
func convertBackendRef(namespace, name, kind string) gatewayv1.BackendRef {
@@ -53,13 +51,13 @@ func (t *Translator) attachBackendTrafficPolicyToUpstream(policy *v1alpha1.Backe
5351
}
5452
if policy.Spec.Timeout != nil {
5553
upstream.Timeout = &adctypes.Timeout{
56-
Connect: int(policy.Spec.Timeout.Connect.Duration.Seconds()),
57-
Read: int(policy.Spec.Timeout.Read.Duration.Seconds()),
58-
Send: int(policy.Spec.Timeout.Send.Duration.Seconds()),
54+
Connect: int(policy.Spec.Timeout.Connect.Seconds()),
55+
Read: int(policy.Spec.Timeout.Read.Seconds()),
56+
Send: int(policy.Spec.Timeout.Send.Seconds()),
5957
}
6058
}
6159
if policy.Spec.LoadBalancer != nil {
62-
upstream.Type = adc.UpstreamType(policy.Spec.LoadBalancer.Type)
60+
upstream.Type = adctypes.UpstreamType(policy.Spec.LoadBalancer.Type)
6361
upstream.HashOn = policy.Spec.LoadBalancer.HashOn
6462
upstream.Key = policy.Spec.LoadBalancer.Key
6563
}

0 commit comments

Comments
 (0)