From 1e54f1cb157574cb22ad2267c0ba5e36b22a3d7c Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Wed, 22 Jan 2025 21:56:44 +0100 Subject: [PATCH] chore: enable var-declaration from revive (#8636) Signed-off-by: Matthieu MOREL --- .github/workflows/pr-codespell.yml | 2 +- .golangci.yaml | 7 +------ internal/volume/volumes_information.go | 2 +- internal/volumehelper/volume_policy_helper_test.go | 4 ++-- pkg/backup/backup.go | 2 +- pkg/cmd/cli/restore/create.go | 2 +- pkg/cmd/const.go | 2 +- pkg/cmd/test/const.go | 4 ++-- pkg/controller/data_download_controller_test.go | 2 +- pkg/controller/data_upload_controller_test.go | 2 +- pkg/controller/restore_controller.go | 2 +- pkg/datapath/micro_service_watcher.go | 2 +- pkg/exposer/csi_snapshot.go | 2 +- pkg/exposer/generic_restore.go | 2 +- pkg/restore/pv_restorer.go | 2 +- pkg/util/kube/event.go | 2 +- pkg/util/kube/pvc_pv.go | 4 ++-- pkg/util/third_party.go | 2 +- 18 files changed, 21 insertions(+), 26 deletions(-) diff --git a/.github/workflows/pr-codespell.yml b/.github/workflows/pr-codespell.yml index 0d3138e403..900371ca2b 100644 --- a/.github/workflows/pr-codespell.yml +++ b/.github/workflows/pr-codespell.yml @@ -13,7 +13,7 @@ jobs: - name: Codespell uses: codespell-project/actions-codespell@master with: - # ignore the config/.../crd.go file as it's generated binary data that is edited elswhere. + # ignore the config/.../crd.go file as it's generated binary data that is edited elsewhere. skip: .git,*.png,*.jpg,*.woff,*.ttf,*.gif,*.ico,./config/crd/v1beta1/crds/crds.go,./config/crd/v1/crds/crds.go,./config/crd/v2alpha1/crds/crds.go,./go.sum,./LICENSE ignore_words_list: iam,aks,ist,bridget,ue,shouldnot,atleast,notin,sme,optin check_filenames: true diff --git a/.golangci.yaml b/.golangci.yaml index 8d2b6c75d2..39e855f0a7 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -240,7 +240,6 @@ linters-settings: - name: context-as-argument disabled: true - name: context-keys-type - disabled: false - name: dot-imports disabled: true - name: early-return @@ -262,7 +261,6 @@ linters-settings: - name: indent-error-flow disabled: true - name: range - disabled: false - name: receiver-naming disabled: true - name: redefines-builtin-id @@ -272,19 +270,16 @@ linters-settings: arguments: - "preserveScope" - name: time-naming - disabled: false - name: unexported-return disabled: true - name: unnecessary-stmt disabled: true - name: unreachable-code - disabled: false - name: unused-parameter disabled: true - name: use-any disabled: true - name: var-declaration - disabled: true - name: var-naming disabled: true @@ -333,7 +328,7 @@ linters-settings: force-case-trailing-whitespace: 0 # Force cuddling of err checks with err var assignment force-err-cuddling: false - # Allow leading comments to be separated with empty liens + # Allow leading comments to be separated with empty lines allow-separated-leading-comment: false linters: diff --git a/internal/volume/volumes_information.go b/internal/volume/volumes_information.go index 9af6d7fe34..a89806ee01 100644 --- a/internal/volume/volumes_information.go +++ b/internal/volume/volumes_information.go @@ -830,7 +830,7 @@ func (t *RestoreVolumeInfoTracker) Result() []*RestoreVolumeInfo { continue } pvcNS, pvcName := n[0], n[1] - var restoreSize int64 = 0 + var restoreSize int64 if csiSnapshot.Status != nil && csiSnapshot.Status.RestoreSize != nil { restoreSize = csiSnapshot.Status.RestoreSize.Value() } diff --git a/internal/volumehelper/volume_policy_helper_test.go b/internal/volumehelper/volume_policy_helper_test.go index 375825e22e..44d7281b96 100644 --- a/internal/volumehelper/volume_policy_helper_test.go +++ b/internal/volumehelper/volume_policy_helper_test.go @@ -314,7 +314,7 @@ func TestVolumeHelperImpl_ShouldPerformSnapshot(t *testing.T) { fakeClient.Create(context.Background(), tc.pod) } - var p *resourcepolicies.Policies = nil + var p *resourcepolicies.Policies if tc.resourcePolicies != nil { p = &resourcepolicies.Policies{} err := p.BuildPolicy(tc.resourcePolicies) @@ -679,7 +679,7 @@ func TestVolumeHelperImpl_ShouldPerformFSBackup(t *testing.T) { fakeClient.Create(context.Background(), tc.pod) } - var p *resourcepolicies.Policies = nil + var p *resourcepolicies.Policies if tc.resourcePolicies != nil { p = &resourcepolicies.Policies{} err := p.BuildPolicy(tc.resourcePolicies) diff --git a/pkg/backup/backup.go b/pkg/backup/backup.go index 280164cc40..a8ecc285c5 100644 --- a/pkg/backup/backup.go +++ b/pkg/backup/backup.go @@ -352,7 +352,7 @@ func (kb *kubernetesBackupper) BackupWithResolvers( } backupRequest.Status.Progress = &velerov1api.BackupProgress{TotalItems: len(items)} - var resourcePolicy *resourcepolicies.Policies = nil + var resourcePolicy *resourcepolicies.Policies if backupRequest.ResPolicies != nil { resourcePolicy = backupRequest.ResPolicies } diff --git a/pkg/cmd/cli/restore/create.go b/pkg/cmd/cli/restore/create.go index 17446f6983..c861bab0d7 100644 --- a/pkg/cmd/cli/restore/create.go +++ b/pkg/cmd/cli/restore/create.go @@ -299,7 +299,7 @@ func (o *CreateOptions) Run(c *cobra.Command, f client.Factory) error { } } - var resModifiers *corev1.TypedLocalObjectReference = nil + var resModifiers *corev1.TypedLocalObjectReference if o.ResourceModifierConfigMap != "" { resModifiers = &corev1.TypedLocalObjectReference{ diff --git a/pkg/cmd/const.go b/pkg/cmd/const.go index 7f44598997..a5434e04e8 100644 --- a/pkg/cmd/const.go +++ b/pkg/cmd/const.go @@ -1,3 +1,3 @@ package cmd -var TRUE string = "true" +var TRUE = "true" diff --git a/pkg/cmd/test/const.go b/pkg/cmd/test/const.go index 0c07fe0fa4..6490bb0f65 100644 --- a/pkg/cmd/test/const.go +++ b/pkg/cmd/test/const.go @@ -1,4 +1,4 @@ package test -var VeleroNameSpace string = "velero-test" -var CaptureFlag string = "CAPTRUE-OUTPUT" +var VeleroNameSpace = "velero-test" +var CaptureFlag = "CAPTRUE-OUTPUT" diff --git a/pkg/controller/data_download_controller_test.go b/pkg/controller/data_download_controller_test.go index 046103771e..9c562d4fbb 100644 --- a/pkg/controller/data_download_controller_test.go +++ b/pkg/controller/data_download_controller_test.go @@ -72,7 +72,7 @@ func dataDownloadBuilder() *builder.DataDownloadBuilder { } func initDataDownloadReconciler(objects []runtime.Object, needError ...bool) (*DataDownloadReconciler, error) { - var errs []error = make([]error, 6) + var errs = make([]error, 6) for k, isError := range needError { if k == 0 && isError { errs[0] = fmt.Errorf("Get error") diff --git a/pkg/controller/data_upload_controller_test.go b/pkg/controller/data_upload_controller_test.go index 0a02108692..ccee39e35a 100644 --- a/pkg/controller/data_upload_controller_test.go +++ b/pkg/controller/data_upload_controller_test.go @@ -121,7 +121,7 @@ func (c *FakeClient) List(ctx context.Context, list kbclient.ObjectList, opts .. } func initDataUploaderReconciler(needError ...bool) (*DataUploadReconciler, error) { - var errs []error = make([]error, 6) + var errs = make([]error, 6) for k, isError := range needError { if k == 0 && isError { errs[0] = fmt.Errorf("Get error") diff --git a/pkg/controller/restore_controller.go b/pkg/controller/restore_controller.go index 336f2e1944..34ff898b8f 100644 --- a/pkg/controller/restore_controller.go +++ b/pkg/controller/restore_controller.go @@ -396,7 +396,7 @@ func (r *restoreReconciler) validateAndComplete(restore *api.Restore) (backupInf restore.Spec.ScheduleName = info.backup.GetLabels()[api.ScheduleNameLabel] } - var resourceModifiers *resourcemodifiers.ResourceModifiers = nil + var resourceModifiers *resourcemodifiers.ResourceModifiers if restore.Spec.ResourceModifier != nil && strings.EqualFold(restore.Spec.ResourceModifier.Kind, resourcemodifiers.ConfigmapRefType) { ResourceModifierConfigMap := &corev1api.ConfigMap{} err := r.kbClient.Get(context.Background(), client.ObjectKey{Namespace: restore.Namespace, Name: restore.Spec.ResourceModifier.Name}, ResourceModifierConfigMap) diff --git a/pkg/datapath/micro_service_watcher.go b/pkg/datapath/micro_service_watcher.go index 02c99299c4..1bac50a99a 100644 --- a/pkg/datapath/micro_service_watcher.go +++ b/pkg/datapath/micro_service_watcher.go @@ -251,7 +251,7 @@ var funcRedirectLog = redirectDataMoverLogs var funcGetResultFromMessage = getResultFromMessage var funcGetProgressFromMessage = getProgressFromMessage -var eventWaitTimeout time.Duration = time.Minute +var eventWaitTimeout = time.Minute func (ms *microServiceBRWatcher) startWatch() { ms.wgWatcher.Add(1) diff --git a/pkg/exposer/csi_snapshot.go b/pkg/exposer/csi_snapshot.go index cfc34cc926..ac878eda45 100644 --- a/pkg/exposer/csi_snapshot.go +++ b/pkg/exposer/csi_snapshot.go @@ -539,7 +539,7 @@ func (e *csiSnapshotExposer) createBackupPod( return nil, errors.Wrap(err, "error to get inherited pod info from node-agent") } - var gracePeriod int64 = 0 + var gracePeriod int64 volumeMounts, volumeDevices, volumePath := kube.MakePodPVCAttachment(volumeName, backupPVC.Spec.VolumeMode, backupPVCReadOnly) volumeMounts = append(volumeMounts, podInfo.volumeMounts...) diff --git a/pkg/exposer/generic_restore.go b/pkg/exposer/generic_restore.go index e5f65e55ed..06c680d8c2 100644 --- a/pkg/exposer/generic_restore.go +++ b/pkg/exposer/generic_restore.go @@ -386,7 +386,7 @@ func (e *genericRestoreExposer) createRestorePod(ctx context.Context, ownerObjec return nil, errors.Wrap(err, "error to get inherited pod info from node-agent") } - var gracePeriod int64 = 0 + var gracePeriod int64 volumeMounts, volumeDevices, volumePath := kube.MakePodPVCAttachment(volumeName, targetPVC.Spec.VolumeMode, false) volumeMounts = append(volumeMounts, podInfo.volumeMounts...) diff --git a/pkg/restore/pv_restorer.go b/pkg/restore/pv_restorer.go index 49d2e885fb..53fbd0126a 100644 --- a/pkg/restore/pv_restorer.go +++ b/pkg/restore/pv_restorer.go @@ -92,7 +92,7 @@ func (r *pvRestorer) executePVAction(obj *unstructured.Unstructured) (*unstructu if !ok { return nil, errors.Errorf("unexpected type %T", updated1) } - var iops int64 = 0 + var iops int64 if snapshotInfo.volumeIOPS != nil { iops = *snapshotInfo.volumeIOPS } diff --git a/pkg/util/kube/event.go b/pkg/util/kube/event.go index 8b5fc9c5b7..69632bd120 100644 --- a/pkg/util/kube/event.go +++ b/pkg/util/kube/event.go @@ -128,7 +128,7 @@ func (er *eventRecorder) EndingEvent(object runtime.Object, warning bool, reason } } -var shutdownTimeout time.Duration = time.Minute +var shutdownTimeout = time.Minute func (er *eventRecorder) Shutdown() { var wait chan struct{} diff --git a/pkg/util/kube/pvc_pv.go b/pkg/util/kube/pvc_pv.go index a80405874b..a9311cab39 100644 --- a/pkg/util/kube/pvc_pv.go +++ b/pkg/util/kube/pvc_pv.go @@ -356,8 +356,8 @@ func IsPVCBound(pvc *corev1api.PersistentVolumeClaim) bool { // MakePodPVCAttachment returns the volume mounts and devices for a pod needed to attach a PVC func MakePodPVCAttachment(volumeName string, volumeMode *corev1api.PersistentVolumeMode, readOnly bool) ([]corev1api.VolumeMount, []corev1api.VolumeDevice, string) { - var volumeMounts []corev1api.VolumeMount = nil - var volumeDevices []corev1api.VolumeDevice = nil + var volumeMounts []corev1api.VolumeMount + var volumeDevices []corev1api.VolumeDevice volumePath := "/" + volumeName if volumeMode != nil && *volumeMode == corev1api.PersistentVolumeBlock { diff --git a/pkg/util/third_party.go b/pkg/util/third_party.go index 2be1586811..b0b73d68ee 100644 --- a/pkg/util/third_party.go +++ b/pkg/util/third_party.go @@ -16,6 +16,6 @@ limitations under the License. package util -var ThirdPartyLabels []string = []string{ +var ThirdPartyLabels = []string{ "azure.workload.identity/use", }