Skip to content

Commit 322961f

Browse files
chore: moar lints
Slowly converge towards what exists on argo-cd. Signed-off-by: Blake Pettersson <[email protected]>
1 parent c449507 commit 322961f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+574
-714
lines changed

.golangci.yml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
formatters:
22
enable:
3+
- gofumpt
34
- goimports
45

56
settings:
@@ -21,17 +22,16 @@ linters:
2122
- govet
2223
- importas
2324
- misspell
25+
- perfsprint
26+
- revive
2427
- staticcheck
28+
- testifylint
2529
- thelper
2630
- tparallel
2731
- unparam
2832
- usestdlibvars
2933
- usetesting
3034
- whitespace
31-
disable:
32-
- perfsprint # Performance optimizations cause many changes
33-
- testifylint # Test assertion order changes cause large diffs
34-
- revive # Too many style changes (265+ issues)
3535

3636
exclusions:
3737
rules:
@@ -154,8 +154,7 @@ linters:
154154
- name: duplicated-imports
155155

156156
- name: early-return
157-
arguments:
158-
- preserveScope
157+
disabled: true
159158

160159
- name: empty-block
161160
disabled: true
@@ -177,8 +176,7 @@ linters:
177176
- name: increment-decrement
178177

179178
- name: indent-error-flow
180-
arguments:
181-
- preserveScope
179+
disabled: true
182180

183181
- name: modifies-parameter
184182

@@ -218,11 +216,7 @@ linters:
218216
- name: var-declaration
219217

220218
- name: var-naming
221-
arguments:
222-
- - ID
223-
- - VM
224-
- - skipPackageNameChecks: true
225-
upperCaseConst: true
219+
disabled: true
226220

227221
staticcheck:
228222
checks:

examples/certmanager/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ notificationsFactory := api.NewFactory(api.Settings{
2727
ConfigMapName: "cert-manager-notifications-cm",
2828
SecretName: "cert-manager-notifications-secret",
2929
InitGetVars: func(cfg *api.Config, configMap *v1.ConfigMap, secret *v1.Secret) (api.GetVars, error) {
30-
return func(obj map[string]interface{}, dest services.Destination) map[string]interface{} {
31-
return map[string]interface{}{"cert": obj}
30+
return func(obj map[string]any, dest services.Destination) map[string]any {
31+
return map[string]any{"cert": obj}
3232
}, nil
3333
},
3434
}, namespace, secrets, configMaps)
@@ -128,8 +128,8 @@ func main() {
128128
ConfigMapName: "cert-manager-notifications-cm",
129129
SecretName: "cert-manager-notifications-secret",
130130
InitGetVars: func(cfg *api.Config, configMap *v1.ConfigMap, secret *v1.Secret) (api.GetVars, error) {
131-
return func(obj map[string]interface{}, dest services.Destination) map[string]interface{} {
132-
return map[string]interface{}{"cert": obj}
131+
return func(obj map[string]any, dest services.Destination) map[string]any {
132+
return map[string]any{"cert": obj}
133133
}, nil
134134
},
135135
})

examples/certmanager/cli/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ func main() {
2020
}, api.Settings{
2121
ConfigMapName: "cert-manager-notifications-cm",
2222
SecretName: "cert-manager-notifications-secret",
23-
InitGetVars: func(cfg *api.Config, configMap *corev1.ConfigMap, secret *corev1.Secret) (api.GetVars, error) {
24-
return func(obj map[string]interface{}, dest services.Destination) map[string]interface{} {
25-
return map[string]interface{}{"cert": obj}
23+
InitGetVars: func(_ *api.Config, _ *corev1.ConfigMap, _ *corev1.Secret) (api.GetVars, error) {
24+
return func(obj map[string]any, _ services.Destination) map[string]any {
25+
return map[string]any{"cert": obj}
2626
}, nil
2727
},
2828
})

examples/certmanager/controller/main.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ import (
2828
)
2929

3030
func main() {
31-
var (
32-
clientConfig clientcmd.ClientConfig
33-
)
34-
var command = cobra.Command{
31+
var clientConfig clientcmd.ClientConfig
32+
command := cobra.Command{
3533
Use: "controller",
36-
Run: func(c *cobra.Command, args []string) {
34+
Run: func(_ *cobra.Command, _ []string) {
3735
// Optionally set the annotations prefix
3836
// subscriptions.SetAnnotationPrefix("example.prefix.io")
3937

@@ -59,9 +57,9 @@ func main() {
5957
notificationsFactory := api.NewFactory(api.Settings{
6058
ConfigMapName: "cert-manager-notifications-cm",
6159
SecretName: "cert-manager-notifications-secret",
62-
InitGetVars: func(cfg *api.Config, configMap *corev1.ConfigMap, secret *corev1.Secret) (api.GetVars, error) {
63-
return func(obj map[string]interface{}, dest services.Destination) map[string]interface{} {
64-
return map[string]interface{}{"cert": obj}
60+
InitGetVars: func(_ *api.Config, _ *corev1.ConfigMap, _ *corev1.Secret) (api.GetVars, error) {
61+
return func(obj map[string]any, _ services.Destination) map[string]any {
62+
return map[string]any{"cert": obj}
6563
}, nil
6664
},
6765
}, namespace, secrets, configMaps)
@@ -74,7 +72,7 @@ func main() {
7472
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
7573
return certClient.List(context.Background(), options)
7674
},
77-
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
75+
WatchFunc: func(_ metav1.ListOptions) (watch.Interface, error) {
7876
return certClient.Watch(context.Background(), metav1.ListOptions{})
7977
},
8078
}, &unstructured.Unstructured{}, time.Minute, cache.Indexers{})

pkg/api/api.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ const (
1515

1616
//go:generate mockgen -destination=../mocks/api.go -package=mocks github.com/argoproj/notifications-engine/pkg/api API
1717

18-
type GetVars func(obj map[string]interface{}, dest services.Destination) map[string]interface{}
18+
type GetVars func(obj map[string]any, dest services.Destination) map[string]any
1919

2020
// API provides high level interface to send notifications and manage notification services
2121
type API interface {
22-
Send(obj map[string]interface{}, templates []string, dest services.Destination) error
23-
RunTrigger(triggerName string, vars map[string]interface{}) ([]triggers.ConditionResult, error)
22+
Send(obj map[string]any, templates []string, dest services.Destination) error
23+
RunTrigger(triggerName string, vars map[string]any) ([]triggers.ConditionResult, error)
2424
AddNotificationService(name string, service services.NotificationService)
2525
GetNotificationServices() map[string]services.NotificationService
2626
GetConfig() Config
@@ -49,15 +49,15 @@ func (n *api) GetNotificationServices() map[string]services.NotificationService
4949
}
5050

5151
// Send sends notification using specified service and template to the specified destination
52-
func (n *api) Send(obj map[string]interface{}, templates []string, dest services.Destination) error {
52+
func (n *api) Send(obj map[string]any, templates []string, dest services.Destination) error {
5353
notificationService, ok := n.notificationServices[dest.Service]
5454
if !ok {
5555
return fmt.Errorf("notification service '%s' is not supported", dest.Service)
5656
}
5757

5858
vars := n.getVars(obj, dest)
5959

60-
in := make(map[string]interface{})
60+
in := make(map[string]any)
6161
for k := range vars {
6262
in[k] = vars[k]
6363
}
@@ -71,7 +71,7 @@ func (n *api) Send(obj map[string]interface{}, templates []string, dest services
7171
return notificationService.Send(*notification, dest)
7272
}
7373

74-
func (n *api) RunTrigger(triggerName string, obj map[string]interface{}) ([]triggers.ConditionResult, error) {
74+
func (n *api) RunTrigger(triggerName string, obj map[string]any) ([]triggers.ConditionResult, error) {
7575
vars := n.getVars(obj, services.Destination{})
7676
return n.triggersService.Run(triggerName, vars)
7777
}

pkg/api/api_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import (
55

66
"github.com/golang/mock/gomock"
77
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
89

910
"github.com/argoproj/notifications-engine/pkg/services"
1011
"github.com/argoproj/notifications-engine/pkg/services/mocks"
1112
)
1213

13-
func getVars(in map[string]interface{}, _ services.Destination) map[string]interface{} {
14+
func getVars(in map[string]any, _ services.Destination) map[string]any {
1415
return in
1516
}
1617

@@ -32,6 +33,7 @@ func getConfig(ctrl *gomock.Controller, opts ...func(service *mocks.MockNotifica
3233
},
3334
}
3435
}
36+
3537
func TestSend(t *testing.T) {
3638
ctrl := gomock.NewController(t)
3739
defer ctrl.Finish()
@@ -44,12 +46,10 @@ func TestSend(t *testing.T) {
4446
Recipient: "my-channel",
4547
}).Return(nil)
4648
}), getVars)
47-
if !assert.NoError(t, err) {
48-
return
49-
}
49+
require.NoError(t, err)
5050

5151
err = api.Send(
52-
map[string]interface{}{"foo": "world"},
52+
map[string]any{"foo": "world"},
5353
[]string{"my-template"},
5454
services.Destination{Service: "slack", Recipient: "my-channel"},
5555
)
@@ -61,9 +61,7 @@ func TestAddService(t *testing.T) {
6161
defer ctrl.Finish()
6262

6363
api, err := NewAPI(getConfig(ctrl), getVars)
64-
if !assert.NoError(t, err) {
65-
return
66-
}
64+
require.NoError(t, err)
6765

6866
api.AddNotificationService("hello", mocks.NewMockNotificationService(ctrl))
6967

pkg/api/config_test.go

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,21 @@ import (
77
"github.com/argoproj/notifications-engine/pkg/subscriptions"
88

99
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
1011
corev1 "k8s.io/api/core/v1"
1112
"k8s.io/apimachinery/pkg/labels"
1213
)
1314

14-
var (
15-
emptySecret = &corev1.Secret{Data: map[string][]byte{}}
16-
)
15+
var emptySecret = &corev1.Secret{Data: map[string][]byte{}}
1716

1817
func TestParseConfig_Services(t *testing.T) {
1918
cfg, err := ParseConfig(&corev1.ConfigMap{Data: map[string]string{
2019
"service.slack": `
2120
token: my-token
22-
`}}, emptySecret)
21+
`,
22+
}}, emptySecret)
2323

24-
if !assert.NoError(t, err) {
25-
return
26-
}
24+
require.NoError(t, err)
2725

2826
assert.NotNil(t, cfg.Services["slack"])
2927
}
@@ -32,11 +30,10 @@ func TestParseConfig_Templates(t *testing.T) {
3230
cfg, err := ParseConfig(&corev1.ConfigMap{Data: map[string]string{
3331
"template.my-template": `
3432
message: hello world
35-
`}}, emptySecret)
33+
`,
34+
}}, emptySecret)
3635

37-
if !assert.NoError(t, err) {
38-
return
39-
}
36+
require.NoError(t, err)
4037

4138
assert.Equal(t, map[string]services.Notification{
4239
"my-template": {Message: "hello world"},
@@ -48,11 +45,10 @@ func TestParseConfig_DefaultServiceTriggers(t *testing.T) {
4845
"defaultTriggers.slack": `
4946
- trigger-a
5047
- trigger-b
51-
`}}, emptySecret)
48+
`,
49+
}}, emptySecret)
5250

53-
if !assert.NoError(t, err) {
54-
return
55-
}
51+
require.NoError(t, err)
5652

5753
assert.Equal(t, map[string][]string{
5854
"slack": {
@@ -100,7 +96,7 @@ headers:
10096

10197
result, err := replaceServiceConfigSecrets(input, &secrets)
10298

103-
assert.NoError(t, err)
99+
require.NoError(t, err)
104100
assert.Equal(t, expected, string(result))
105101
}
106102

@@ -126,7 +122,7 @@ apiKeys:
126122

127123
result, err := replaceServiceConfigSecrets(input, &secrets)
128124

129-
assert.NoError(t, err)
125+
require.NoError(t, err)
130126
assert.Equal(t, expected, string(result))
131127
}
132128

@@ -154,7 +150,7 @@ installationID: 67890
154150

155151
result, err := replaceServiceConfigSecrets(input, &secrets)
156152

157-
assert.NoError(t, err)
153+
require.NoError(t, err)
158154
assert.Equal(t, expected, string(result))
159155
}
160156

@@ -165,9 +161,7 @@ func TestParseConfig_DefaultTriggers(t *testing.T) {
165161
},
166162
}, emptySecret)
167163

168-
if !assert.NoError(t, err) {
169-
return
170-
}
164+
require.NoError(t, err)
171165
assert.Equal(t, []string{"trigger1", "trigger2"}, cfg.DefaultTriggers)
172166
}
173167

@@ -181,14 +175,10 @@ func TestParseConfig_Subscriptions(t *testing.T) {
181175
},
182176
}, emptySecret)
183177

184-
if !assert.NoError(t, err) {
185-
return
186-
}
178+
require.NoError(t, err)
187179

188180
label, err := labels.Parse("test=true")
189-
if !assert.NoError(t, err) {
190-
return
191-
}
181+
require.NoError(t, err)
192182
assert.Equal(t, subscriptions.DefaultSubscriptions([]subscriptions.DefaultSubscription{
193183
{Triggers: []string{"my-trigger2"}, Selector: label},
194184
}), cfg.Subscriptions)

pkg/api/factory.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,33 @@ func NewFactory(settings Settings, defaultNamespace string, secretsInformer cach
5858
}
5959

6060
_, _ = secretsInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
61-
AddFunc: func(obj interface{}) {
61+
AddFunc: func(obj any) {
6262
factory.invalidateIfHasName(settings.SecretName, obj)
6363
},
64-
DeleteFunc: func(obj interface{}) {
64+
DeleteFunc: func(obj any) {
6565
factory.invalidateIfHasName(settings.SecretName, obj)
6666
},
67-
UpdateFunc: func(oldObj, newObj interface{}) {
67+
UpdateFunc: func(_, newObj any) {
6868
factory.invalidateIfHasName(settings.SecretName, newObj)
69-
}})
69+
},
70+
})
7071

7172
_, _ = cmInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
72-
AddFunc: func(obj interface{}) {
73+
AddFunc: func(obj any) {
7374
factory.invalidateIfHasName(settings.ConfigMapName, obj)
7475
},
75-
DeleteFunc: func(obj interface{}) {
76+
DeleteFunc: func(obj any) {
7677
factory.invalidateIfHasName(settings.ConfigMapName, obj)
7778
},
78-
UpdateFunc: func(oldObj, newObj interface{}) {
79+
UpdateFunc: func(_, newObj any) {
7980
factory.invalidateIfHasName(settings.ConfigMapName, newObj)
80-
}})
81+
},
82+
})
8183

8284
return factory
8385
}
8486

85-
func (f *apiFactory) invalidateIfHasName(name string, obj interface{}) {
87+
func (f *apiFactory) invalidateIfHasName(name string, obj any) {
8688
metaObj, ok := obj.(metav1.Object)
8789
if !ok {
8890
return

0 commit comments

Comments
 (0)