Skip to content

Commit db4ec44

Browse files
committed
Update to golangci-lint v2.5.0
Signed-off-by: Fredrik Lönnegren <[email protected]>
1 parent 4dfd8fa commit db4ec44

File tree

7 files changed

+133
-33
lines changed

7 files changed

+133
-33
lines changed

.golangci.yml

Lines changed: 120 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,137 @@
1+
version: "2"
12
run:
2-
deadline: 5m
3+
go: "1.24"
4+
timeout: 10m
5+
modules-download-mode: readonly
36
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
197
linters:
20-
disable-all: true
8+
# sync from https://github.com/kubernetes-sigs/controller-runtime/blob/main/.golangci.yml
9+
default: none
2110
enable:
11+
- asasalint
12+
- asciicheck
13+
- bidichk
14+
- bodyclose
15+
- copyloopvar
16+
- dogsled
2217
- dupl
2318
- errcheck
24-
- exportloopref
19+
- errchkjson
20+
- errorlint
21+
- forbidigo
22+
- ginkgolinter
2523
- goconst
24+
- gocritic
2625
- gocyclo
27-
- gofmt
28-
- goimports
29-
- gosimple
26+
- godoclint
27+
- goprintffuncname
3028
- govet
29+
- importas
3130
- ineffassign
31+
- iotamixing
32+
- makezero
3233
- misspell
3334
- nakedret
35+
- nilerr
36+
- nolintlint
3437
- prealloc
38+
- revive
3539
- staticcheck
36-
- typecheck
40+
- tagliatelle
3741
- unconvert
3842
- unparam
3943
- unused
44+
- whitespace
45+
settings:
46+
forbidigo:
47+
forbid:
48+
- pattern: context.Background
49+
msg: Use ginkgos SpecContext or go testings t.Context instead
50+
- pattern: context.TODO
51+
msg: Use ginkgos SpecContext or go testings t.Context instead
52+
govet:
53+
disable:
54+
- fieldalignment
55+
- shadow
56+
enable-all: true
57+
importas:
58+
no-unaliased: true
59+
revive:
60+
# By default, revive will enable only the linting rules that are named in the configuration file.
61+
# So, it's needed to explicitly enable all required rules here.
62+
rules:
63+
# The following rules are recommended https://github.com/mgechev/revive#recommended-configuration
64+
- name: blank-imports
65+
- name: context-as-argument
66+
- name: context-keys-type
67+
- name: dot-imports
68+
- name: error-return
69+
- name: error-strings
70+
- name: error-naming
71+
- name: if-return
72+
- name: increment-decrement
73+
- name: var-naming
74+
- name: var-declaration
75+
- name: range
76+
- name: receiver-naming
77+
- name: time-naming
78+
- name: unexported-return
79+
- name: indent-error-flow
80+
- name: errorf
81+
- name: superfluous-else
82+
- name: unreachable-code
83+
- name: redefines-builtin-id
84+
#
85+
# Rules in addition to the recommended configuration above.
86+
#
87+
- name: bool-literal-in-expr
88+
- name: constant-logical-expr
89+
exclusions:
90+
generated: strict
91+
paths:
92+
- zz_generated.*\.go$
93+
- .*conversion.*\.go$
94+
presets:
95+
- comments
96+
- common-false-positives
97+
- legacy
98+
- std-error-handling
99+
rules:
100+
# Dot imports for gomega and ginkgo are allowed
101+
# within test files.
102+
- linters:
103+
- revive
104+
path: _test\.go
105+
text: should not use dot imports
106+
# Ignore error type switch case
107+
- linters:
108+
- errorlint
109+
path: pkg/loader/loader.go
110+
# Ignore test files
111+
- linters:
112+
- dupl
113+
- ginkgolinter
114+
path: _test\.go
115+
- linters:
116+
- gocritic
117+
path: pkg/markers/help.go
118+
- linters:
119+
- exhaustive
120+
path: pkg/markers/parse.go|pkg/deepcopy/traverse.go|pkg/genall/help/types.go|pkg/crd/schema.go|pkg/crd/flatten.go
121+
# Ignore consider pre-allocating variables
122+
- linters:
123+
- prealloc
124+
text: Consider pre-allocating
125+
- linters:
126+
- staticcheck
127+
path: (.+)\.go$
128+
text: (QF1008)
129+
formatters:
130+
enable:
131+
- gofmt
132+
- goimports
133+
exclusions:
134+
generated: strict
135+
paths:
136+
- zz_generated.*\.go$
137+
- .*conversion.*\.go$

api/v1beta1/rtlsdrreceiver_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type RtlSdrReceiverSpec struct {
4242
ContainerPort *corev1.ContainerPort `json:"port"`
4343
}
4444

45+
// RtlSdrVersion is the major version of the rtl-sdr receiver.
4546
// +kubebuilder:validation:Enum=v3;v4
4647
type RtlSdrVersion string
4748

@@ -65,6 +66,7 @@ type RtlSdrReceiverStatus struct {
6566
Pod *corev1.ObjectReference `json:"pod,omitempty"`
6667
}
6768

69+
// RtlSdrReceiverState state of the rtl-sdr receiver.
6870
// +kubebuilder:validation:Enum=Waiting;Running;Failed
6971
type RtlSdrReceiverState string
7072

cmd/device-plugin/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import (
44
"flag"
55
"time"
66

7-
rtlsdr "github.com/frelon/k8s-radio/device-plugin/rtl-sdr"
87
"github.com/golang/glog"
98
"github.com/kubevirt/device-plugin-manager/pkg/dpm"
9+
10+
rtlsdr "github.com/frelon/k8s-radio/device-plugin/rtl-sdr"
1011
)
1112

1213
type RadioDeviceLister struct {
@@ -30,8 +31,7 @@ func (l *RadioDeviceLister) Discover(pluginListCh chan dpm.PluginNameList) {
3031
}
3132

3233
func (l *RadioDeviceLister) NewPlugin(resourceLastName string) dpm.PluginInterface {
33-
switch resourceLastName {
34-
case rtlsdr.ResourceName:
34+
if resourceLastName == rtlsdr.ResourceName {
3535
return &rtlsdr.Plugin{
3636
Heartbeat: l.Heartbeat,
3737
RtlSdrs: make(map[string]*rtlsdr.RtlSdrDev),

cmd/manager/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,13 @@ func main() {
9595
image = controller.RtlSdrDefaultImage
9696
}
9797

98+
ctx := ctrl.SetupSignalHandler()
99+
98100
if err = (&controller.RtlSdrReceiverReconciler{
99101
Client: mgr.GetClient(),
100102
Scheme: mgr.GetScheme(),
101103
Image: image,
102-
}).SetupWithManager(mgr); err != nil {
104+
}).SetupWithManager(ctx, mgr); err != nil {
103105
setupLog.Error(err, "unable to create controller", "controller", "RtlSdrReceiver")
104106
os.Exit(1)
105107
}
@@ -115,7 +117,7 @@ func main() {
115117
}
116118

117119
setupLog.Info("starting manager")
118-
if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
120+
if err := mgr.Start(ctx); err != nil {
119121
setupLog.Error(err, "problem running manager")
120122
os.Exit(1)
121123
}

device-plugin/rtl-sdr/rtl-sdr.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ func (p *Plugin) GetDevices() []*pluginapi.Device {
6666
}
6767

6868
func (p *Plugin) ListAndWatch(e *pluginapi.Empty, s pluginapi.DevicePlugin_ListAndWatchServer) error {
69-
7069
err := p.UpdateDevices()
7170
if err != nil {
7271
glog.Errorf("Error listing devices: %s", err.Error())

internal/controller/rtlsdrreceiver_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type RtlSdrReceiverReconciler struct {
5050
Image string
5151
}
5252

53+
// Reconcile reconsiles the resources.
5354
// +kubebuilder:rbac:groups=radio.frelon.se,resources=rtlsdrreceivers,verbs=get;list;watch;create;update;patch;delete
5455
// +kubebuilder:rbac:groups=radio.frelon.se,resources=rtlsdrreceivers/status,verbs=get;update;patch
5556
// +kubebuilder:rbac:groups=radio.frelon.se,resources=rtlsdrreceivers/finalizers,verbs=update
@@ -164,8 +165,8 @@ var (
164165
)
165166

166167
// SetupWithManager sets up the controller with the Manager.
167-
func (r *RtlSdrReceiverReconciler) SetupWithManager(mgr ctrl.Manager) error {
168-
if err := mgr.GetFieldIndexer().IndexField(context.Background(), &corev1.Pod{}, jobOwnerKey, func(rawObj client.Object) []string {
168+
func (r *RtlSdrReceiverReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error {
169+
if err := mgr.GetFieldIndexer().IndexField(ctx, &corev1.Pod{}, jobOwnerKey, func(rawObj client.Object) []string {
169170
// grab the pod object, extract the owner...
170171
pod := rawObj.(*corev1.Pod)
171172
owner := metav1.GetControllerOf(pod)

internal/controller/rtlsdrreceiver_controller_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package controller
22

33
import (
4-
"context"
54
"time"
65

76
. "github.com/onsi/ginkgo/v2"
@@ -33,10 +32,9 @@ var _ = Describe("RtlSdrReceiver controller", func() {
3332
utilruntime.Must(radiov1.AddToScheme(scheme))
3433

3534
Context("When updating RtlSdrReceiver Status", func() {
36-
It("Should successfully create a new RtlSdrReceiver", func() {
35+
It("Should successfully create a new RtlSdrReceiver", func(ctx SpecContext) {
3736
By("By creating a new RtlSdrReceiver")
3837

39-
ctx := context.Background()
4038
freq, err := resource.ParseQuantity("101.9M")
4139
Expect(err).To(Succeed())
4240

0 commit comments

Comments
 (0)