Skip to content

Commit 14d7e9f

Browse files
authored
Merge pull request #5653 from sbueringer/pr-remove-nolintifshort
🐛 Improve nolint linter config, fix ifshort flake
2 parents d8bcb0f + c1da712 commit 14d7e9f

File tree

15 files changed

+28
-18
lines changed

15 files changed

+28
-18
lines changed

.golangci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ linters-settings:
7070
# Controller Runtime
7171
- pkg: sigs.k8s.io/controller-runtime
7272
alias: ctrl
73+
nolintlint:
74+
allow-unused: false
75+
allow-leading-space: false
76+
require-specific: true
7377
staticcheck:
7478
go: "1.17"
7579
stylecheck:
@@ -165,6 +169,12 @@ issues:
165169
- typecheck
166170
text: import (".+") is a program, not an importable package
167171
path: ^tools\.go$
172+
# Ignore ifshort false positive
173+
# TODO(sbueringer) false positive: https://github.com/esimonov/ifshort/issues/23
174+
- linters:
175+
- ifshort
176+
text: "variable 'isDeleteNodeAllowed' is only used in the if-statement.*"
177+
path: ^controllers/machine_controller\.go$
168178

169179
run:
170180
timeout: 10m

cmd/clusterctl/client/config/reader_memory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (f *MemoryReader) Set(key, value string) {
7575
func (f *MemoryReader) UnmarshalKey(key string, rawval interface{}) error {
7676
data, err := f.Get(key)
7777
if err != nil {
78-
return nil // nolint:nilerr // We expect to not error if the key is not present
78+
return nil //nolint:nilerr // We expect to not error if the key is not present
7979
}
8080
return yaml.Unmarshal([]byte(data), rawval)
8181
}

cmd/clusterctl/client/repository/repository_versions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ func latestContractRelease(repo Repository, contract string) (string, error) {
4242
file, err := repo.GetFile(latest, metadataFile)
4343
if err != nil {
4444
// if we can't get the metadata file from the release, we return latest.
45-
return latest, nil // nolint:nilerr
45+
return latest, nil //nolint:nilerr
4646
}
4747
latestMetadata := &clusterctlv1.Metadata{}
4848
codecFactory := serializer.NewCodecFactory(scheme.Scheme)
4949
if err := runtime.DecodeInto(codecFactory.UniversalDecoder(), file, latestMetadata); err != nil {
50-
return latest, nil // nolint:nilerr
50+
return latest, nil //nolint:nilerr
5151
}
5252

5353
releaseSeries := latestMetadata.GetReleaseSeriesForContract(contract)
@@ -57,7 +57,7 @@ func latestContractRelease(repo Repository, contract string) (string, error) {
5757

5858
sv, err := version.ParseSemantic(latest)
5959
if err != nil {
60-
return latest, nil // nolint:nilerr
60+
return latest, nil //nolint:nilerr
6161
}
6262

6363
// If the Major or Minor version of the latest release doesn't match the release series for the current contract,

cmd/clusterctl/cmd/version_checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (v *versionChecker) getLatestRelease() (*ReleaseInfo, error) {
145145
log.V(1).Info("⚠️ Unable to get latest github release for clusterctl")
146146
// failing silently here so we don't error out in air-gapped
147147
// environments.
148-
return nil, nil // nolint:nilerr
148+
return nil, nil //nolint:nilerr
149149
}
150150

151151
vs = &VersionState{

cmd/clusterctl/internal/test/fake_proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (f *FakeProxy) CheckClusterAvailable() error {
9494

9595
// ListResources returns all the resources known by the FakeProxy.
9696
func (f *FakeProxy) ListResources(labels map[string]string, namespaces ...string) ([]unstructured.Unstructured, error) {
97-
var ret []unstructured.Unstructured //nolint
97+
var ret []unstructured.Unstructured //nolint:prealloc
9898
for _, o := range f.objs {
9999
u := unstructured.Unstructured{}
100100
err := FakeScheme.Convert(o, &u, nil)

cmd/clusterctl/internal/test/fake_reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (f *FakeReader) Set(key, value string) {
7373
func (f *FakeReader) UnmarshalKey(key string, rawval interface{}) error {
7474
data, err := f.Get(key)
7575
if err != nil {
76-
return nil // nolint:nilerr // We expect to not error if the key is not present
76+
return nil //nolint:nilerr // We expect to not error if the key is not present
7777
}
7878
return yaml.Unmarshal([]byte(data), rawval)
7979
}

controllers/cluster_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ func (c clusterDescendants) filterOwnedDescendants(cluster *clusterv1.Cluster) (
430430
obj := o.(client.Object)
431431
acc, err := meta.Accessor(obj)
432432
if err != nil {
433-
return nil // nolint:nilerr // We don't want to exit the EachListItem loop, just continue
433+
return nil //nolint:nilerr // We don't want to exit the EachListItem loop, just continue
434434
}
435435

436436
if util.IsOwnedByObject(acc, cluster) {

controllers/machine_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func (r *MachineReconciler) reconcileDelete(ctx context.Context, cluster *cluste
277277
log := ctrl.LoggerFrom(ctx, "cluster", cluster.Name)
278278

279279
err := r.isDeleteNodeAllowed(ctx, cluster, m)
280-
isDeleteNodeAllowed := err == nil //nolint:ifshort
280+
isDeleteNodeAllowed := err == nil
281281
if err != nil {
282282
switch err {
283283
case errNoControlPlaneNodes, errLastControlPlaneNode, errNilNodeRef, errClusterIsBeingDeleted, errControlPlaneIsBeingDeleted:

controllers/machine_controller_phases.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var (
4646
)
4747

4848
func (r *MachineReconciler) reconcilePhase(_ context.Context, m *clusterv1.Machine) {
49-
originalPhase := m.Status.Phase // nolint:ifshort
49+
originalPhase := m.Status.Phase //nolint:ifshort // Cannot be inlined because m.Status.Phase might be changed before it is used in the if.
5050

5151
// Set the phase to "pending" if nil.
5252
if m.Status.Phase == "" {

controllers/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (matcher *refGroupKindMatcher) Match(actual interface{}) (success bool, err
152152
for _, ref := range ownerRefs {
153153
gv, err := schema.ParseGroupVersion(ref.APIVersion)
154154
if err != nil {
155-
return false, nil // nolint:nilerr // If we can't get the group version we can't match, but it's not a failure
155+
return false, nil //nolint:nilerr // If we can't get the group version we can't match, but it's not a failure
156156
}
157157
if ref.Kind == matcher.kind && gv.Group == clusterv1.GroupVersion.Group {
158158
return true, nil

0 commit comments

Comments
 (0)