Skip to content

Commit b90ac7f

Browse files
blakepetterssoncrenshaw-dev
authored andcommitted
chore: bump golanglint-ci (#383)
There's a major upgrade of it. This is an initial upgrade to make the changes as minimal as possible. Signed-off-by: Blake Pettersson <[email protected]> Co-authored-by: Michael Crenshaw <[email protected]> Signed-off-by: Afzal Ansari <[email protected]>
1 parent b3675e3 commit b90ac7f

File tree

19 files changed

+208
-42
lines changed

19 files changed

+208
-42
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ jobs:
2525
- name: Checkout code
2626
uses: actions/checkout@v3
2727
- name: Run golangci-lint
28-
uses: golangci/golangci-lint-action@v3
28+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
2929
with:
30-
version: v1.64.5
31-
args: --timeout 5m
30+
# renovate: datasource=go packageName=github.com/golangci/golangci-lint versioning=regex:^v(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)?$
31+
version: v2.2.1
32+
args: --timeout 5m --verbose
3233
test:
3334
runs-on: ubuntu-latest
3435
steps:

.golangci.yml

Lines changed: 170 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,173 @@
1-
linters-settings:
2-
goimports:
3-
local-prefixes: github.com/argoproj/notifications-engine
1+
formatters:
2+
enable:
3+
- goimports
4+
5+
settings:
6+
goimports:
7+
local-prefixes:
8+
- github.com/argoproj/notifications-engine
9+
10+
issues:
11+
max-issues-per-linter: 0
12+
max-same-issues: 0
413

514
linters:
615
enable:
7-
- goimports
16+
- errorlint
17+
- gomodguard
18+
- misspell
19+
- testifylint
20+
- thelper
21+
- usestdlibvars
22+
- whitespace
23+
disable:
24+
- staticcheck
25+
26+
exclusions:
27+
rules:
28+
- linters:
29+
- unparam
30+
path: (.+)_test\.go
31+
32+
presets:
33+
- comments
34+
- common-false-positives
35+
- legacy
36+
- std-error-handling
37+
38+
warn-unused: true
39+
40+
settings:
41+
gocritic:
42+
disabled-checks:
43+
- appendAssign
44+
- assignOp
45+
- exitAfterDefer
46+
- mapKey
47+
- typeSwitchVar
48+
49+
gomodguard:
50+
blocked:
51+
modules:
52+
- github.com/golang-jwt/jwt/v4:
53+
recommendations:
54+
- github.com/golang-jwt/jwt/v5
55+
56+
- github.com/imdario/mergo:
57+
recommendations:
58+
- dario.cat/mergo
59+
reason: '`github.com/imdario/mergo` has been renamed.'
60+
61+
- github.com/pkg/errors:
62+
recommendations:
63+
- errors
64+
65+
importas:
66+
alias:
67+
- pkg: github.com/golang-jwt/jwt/v5
68+
alias: jwtgo
69+
- pkg: k8s.io/api/apps/v1
70+
alias: appsv1
71+
- pkg: k8s.io/api/core/v1
72+
alias: corev1
73+
- pkg: k8s.io/api/rbac/v1
74+
alias: rbacv1
75+
- pkg: k8s.io/apimachinery/pkg/api/errors
76+
alias: apierrors
77+
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
78+
alias: apiextensionsv1
79+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
80+
alias: metav1
81+
- pkg: k8s.io/client-go/informers/core/v1
82+
alias: informersv1
83+
- pkg: errors
84+
alias: stderrors
85+
86+
nolintlint:
87+
require-specific: true
88+
89+
perfsprint:
90+
# Optimizes even if it requires an int or uint type cast.
91+
int-conversion: true
92+
# Optimizes into `err.Error()` even if it is only equivalent for non-nil errors.
93+
err-error: true
94+
# Optimizes `fmt.Errorf`.
95+
errorf: true
96+
# Optimizes `fmt.Sprintf` with only one argument.
97+
sprintf1: true
98+
# Optimizes into strings concatenation.
99+
strconcat: true
100+
101+
revive:
102+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
103+
rules:
104+
- name: bool-literal-in-expr
105+
- name: blank-imports
106+
disabled: true
107+
- name: context-as-argument
108+
arguments:
109+
- allowTypesBefore: '*testing.T,testing.TB'
110+
- name: context-keys-type
111+
disabled: true
112+
- name: dot-imports
113+
disabled: true
114+
- name: duplicated-imports
115+
- name: empty-block
116+
disabled: true
117+
- name: error-naming
118+
disabled: true
119+
- name: error-return
120+
- name: error-strings
121+
disabled: true
122+
- name: errorf
123+
- name: identical-branches
124+
- name: if-return
125+
- name: increment-decrement
126+
- name: indent-error-flow
127+
arguments:
128+
- preserveScope
129+
- name: modifies-parameter
130+
- name: optimize-operands-order
131+
- name: range
132+
- name: receiver-naming
133+
- name: redefines-builtin-id
134+
disabled: true
135+
- name: redundant-import-alias
136+
- name: superfluous-else
137+
arguments:
138+
- preserveScope
139+
- name: time-equal
140+
- name: time-naming
141+
disabled: true
142+
- name: unexported-return
143+
disabled: true
144+
- name: unnecessary-stmt
145+
- name: unreachable-code
146+
- name: unused-parameter
147+
- name: use-any
148+
- name: useless-break
149+
- name: var-declaration
150+
151+
staticcheck:
152+
checks:
153+
- all
154+
- -SA5011
155+
- -ST1003
156+
- -ST1016
157+
158+
testifylint:
159+
enable-all: true
160+
disable:
161+
- go-require
162+
- expected-actual
163+
- require-error
164+
- len
165+
- empty
166+
- error-nil
167+
- bool-compare
168+
169+
usetesting:
170+
os-mkdir-temp: false
171+
output:
172+
show-stats: false
173+
version: "2"

pkg/api/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func ParseConfig(configMap *v1.ConfigMap, secret *v1.Secret) (*Config, error) {
9999
name := strings.Join(parts[1:], ".")
100100
template := services.Notification{}
101101
if err := yaml.Unmarshal([]byte(v), &template); err != nil {
102-
return nil, fmt.Errorf("failed to unmarshal template %s: %v", name, err)
102+
return nil, fmt.Errorf("failed to unmarshal template %s: %w", name, err)
103103
}
104104
cfg.Templates[name] = template
105105
case strings.HasPrefix(k, "service."):
@@ -116,7 +116,7 @@ func ParseConfig(configMap *v1.ConfigMap, secret *v1.Secret) (*Config, error) {
116116

117117
optsData, err := replaceServiceConfigSecrets(v, secret)
118118
if err != nil {
119-
return nil, fmt.Errorf("failed to render service configuration %s: %v", serviceType, err)
119+
return nil, fmt.Errorf("failed to render service configuration %s: %w", serviceType, err)
120120
}
121121

122122
cfg.Services[name] = func() (services.NotificationService, error) {
@@ -126,14 +126,14 @@ func ParseConfig(configMap *v1.ConfigMap, secret *v1.Secret) (*Config, error) {
126126
name := strings.Join(parts[1:], ".")
127127
var trigger []triggers.Condition
128128
if err := yaml.Unmarshal([]byte(v), &trigger); err != nil {
129-
return nil, fmt.Errorf("failed to unmarshal trigger %s: %v", name, err)
129+
return nil, fmt.Errorf("failed to unmarshal trigger %s: %w", name, err)
130130
}
131131
cfg.Triggers[name] = trigger
132132
case strings.HasPrefix(k, "defaultTriggers."):
133133
name := strings.Join(parts[1:], ".")
134134
var defaultTriggers []string
135135
if err := yaml.Unmarshal([]byte(v), &defaultTriggers); err != nil {
136-
return nil, fmt.Errorf("failed to unmarshal default trigger %s: %v", name, err)
136+
return nil, fmt.Errorf("failed to unmarshal default trigger %s: %w", name, err)
137137
}
138138
cfg.ServiceDefaultTriggers[name] = defaultTriggers
139139
}

pkg/api/factory.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ func (f *apiFactory) getApiFromNamespace(namespace string) (API, error) {
178178
return nil, err
179179
}
180180
return f.getApiFromConfigmapAndSecret(cm, secret)
181-
182181
}
183182

184183
func (f *apiFactory) getApiFromConfigmapAndSecret(cm *v1.ConfigMap, secret *v1.Secret) (API, error) {

pkg/cmd/context.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"bytes"
55
"context"
6+
"errors"
67
"fmt"
78
"io"
89
"os"
@@ -43,18 +44,18 @@ func splitYAML(yamlData []byte) ([]*unstructured.Unstructured, error) {
4344
for {
4445
ext := runtime.RawExtension{}
4546
if err := d.Decode(&ext); err != nil {
46-
if err == io.EOF {
47+
if errors.Is(err, io.EOF) {
4748
break
4849
}
49-
return objs, fmt.Errorf("failed to unmarshal manifest: %v", err)
50+
return objs, fmt.Errorf("failed to unmarshal manifest: %w", err)
5051
}
5152
ext.Raw = bytes.TrimSpace(ext.Raw)
5253
if len(ext.Raw) == 0 || bytes.Equal(ext.Raw, []byte("null")) {
5354
continue
5455
}
5556
u := &unstructured.Unstructured{}
5657
if err := yaml.Unmarshal(ext.Raw, u); err != nil {
57-
return objs, fmt.Errorf("failed to unmarshal manifest: %v", err)
58+
return objs, fmt.Errorf("failed to unmarshal manifest: %w", err)
5859
}
5960
objs = append(objs, u)
6061
}

pkg/controller/controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (c *notificationController) processResourceWithAPI(api api.API, resource v1
205205
res, err := api.RunTrigger(trigger, un.Object)
206206
if err != nil {
207207
logEntry.Errorf("Failed to execute condition of trigger %s: %v using the configuration in namespace %s", trigger, err, apiNamespace)
208-
eventSequence.addWarning(fmt.Errorf("failed to execute condition of trigger %s: %v using the configuration in namespace %s", trigger, err, apiNamespace))
208+
eventSequence.addWarning(fmt.Errorf("failed to execute condition of trigger %s: %w using the configuration in namespace %s", trigger, err, apiNamespace))
209209
}
210210
logEntry.Infof("Trigger %s result: %v", trigger, res)
211211

@@ -234,7 +234,7 @@ func (c *notificationController) processResourceWithAPI(api api.API, resource v1
234234
to, resource.GetNamespace(), resource.GetName(), err, apiNamespace)
235235
notificationsState.SetAlreadyNotified(c.isSelfServiceConfigureApi(api), apiNamespace, trigger, cr, to, false)
236236
c.metricsRegistry.IncDeliveriesCounter(trigger, to.Service, false)
237-
eventSequence.addError(fmt.Errorf("failed to deliver notification %s to %s: %v using the configuration in namespace %s", trigger, to, err, apiNamespace))
237+
eventSequence.addError(fmt.Errorf("failed to deliver notification %s to %s: %w using the configuration in namespace %s", trigger, to, err, apiNamespace))
238238
} else {
239239
logEntry.Debugf("Notification %s was sent using the configuration in namespace %s", to.Recipient, apiNamespace)
240240
c.metricsRegistry.IncDeliveriesCounter(trigger, to.Service, true)
@@ -374,18 +374,18 @@ func (c *notificationController) processResource(api api.API, resource v1.Object
374374
})
375375
if err != nil {
376376
logEntry.Errorf("Failed to marshal resource patch: %v", err)
377-
eventSequence.addWarning(fmt.Errorf("failed to marshal annotations patch %v", err))
377+
eventSequence.addWarning(fmt.Errorf("failed to marshal annotations patch %w", err))
378378
return
379379
}
380380
resource, err = c.client.Namespace(resource.GetNamespace()).Patch(context.Background(), resource.GetName(), types.MergePatchType, patchData, v1.PatchOptions{})
381381
if err != nil {
382382
logEntry.Errorf("Failed to patch resource: %v", err)
383-
eventSequence.addWarning(fmt.Errorf("failed to patch resource annotations %v", err))
383+
eventSequence.addWarning(fmt.Errorf("failed to patch resource annotations %w", err))
384384
return
385385
}
386386
if err := c.informer.GetStore().Update(resource); err != nil {
387387
logEntry.Warnf("Failed to store update resource in informer: %v", err)
388-
eventSequence.addWarning(fmt.Errorf("failed to store update resource in informer: %v", err))
388+
eventSequence.addWarning(fmt.Errorf("failed to store update resource in informer: %w", err))
389389
return
390390
}
391391
}

pkg/controller/controller_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func newResource(name string, modifiers ...func(app *unstructured.Unstructured))
6666
}
6767

6868
func newController(t *testing.T, ctx context.Context, client dynamic.Interface, opts ...Opts) (*notificationController, *mocks.MockAPI, error) {
69+
t.Helper()
6970
mockCtrl := gomock.NewController(t)
7071
go func() {
7172
<-ctx.Done()
@@ -98,6 +99,7 @@ func newController(t *testing.T, ctx context.Context, client dynamic.Interface,
9899
}
99100

100101
func newControllerWithNamespaceSupport(t *testing.T, ctx context.Context, client dynamic.Interface, opts ...Opts) (*notificationController, map[string]notificationApi.API, error) {
102+
t.Helper()
101103
mockCtrl := gomock.NewController(t)
102104
go func() {
103105
<-ctx.Done()
@@ -340,7 +342,7 @@ func TestWithEventCallback(t *testing.T) {
340342
description: "EventCallback should be invoked with non-nil error on send failure",
341343
sendErr: errors.New("this is a send error"),
342344
expectedErrors: []error{
343-
errors.New("failed to deliver notification my-trigger to {mock recipient}: this is a send error using the configuration in namespace "),
345+
fmt.Errorf("failed to deliver notification my-trigger to {mock recipient}: %w using the configuration in namespace ", errors.New("this is a send error")),
344346
},
345347
},
346348
{
@@ -483,5 +485,4 @@ func TestProcessItemsWithSelfService(t *testing.T) {
483485
assert.Equal(t, expectedDeliveries[i].Trigger, event.Trigger)
484486
assert.Equal(t, expectedDeliveries[i].Destination, event.Destination)
485487
}
486-
487488
}

pkg/services/alertmanager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func (s alertmanagerService) sendOneTarget(ctx context.Context, target string, r
245245

246246
data, err := io.ReadAll(response.Body)
247247
if err != nil {
248-
return fmt.Errorf("unable to read response data: %v", err)
248+
return fmt.Errorf("unable to read response data: %w", err)
249249
}
250250

251251
if response.StatusCode != http.StatusOK {

pkg/services/awssqs.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ func (s awsSqsService) sendMessageInput(queueUrl *string, notif Notification) *s
7272
MessageBody: aws.String(notif.Message),
7373
DelaySeconds: 10,
7474
}
75-
7675
}
7776
func (s awsSqsService) getQueueInput(dest Destination) *sqs.GetQueueUrlInput {
7877
result := &sqs.GetQueueUrlInput{}

pkg/services/awssqs_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ func TestGetTemplater_AwsSqs(t *testing.T) {
4848
}
4949

5050
func TestSend_AwsSqs(t *testing.T) {
51-
5251
// Overriding methods inside, so service.Send could be called.
5352
saveGetQueueURL := GetQueueURL
5453
saveSendMsg := SendMsg

0 commit comments

Comments
 (0)