From 87c858f903307288c0db54234e6a499517ba2616 Mon Sep 17 00:00:00 2001 From: Tim Ebert Date: Mon, 9 Sep 2024 15:59:43 +0200 Subject: [PATCH] Format and improve linter settings --- .golangci.yml | 116 +++++++++--------- .../loadbalancermachine_controller.go | 28 ++--- 2 files changed, 69 insertions(+), 75 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 218ad899..4ecd3a03 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,30 +6,21 @@ linters-settings: statements: 50 gocritic: enabled-tags: - - diagnostic - - experimental - - opinionated - - performance - - style + - diagnostic + - experimental + - opinionated + - performance + - style disabled-checks: - - dupImport # https://github.com/go-critic/go-critic/issues/845 - - ifElseChain - - octalLiteral - - whyNoLint - - wrapperFunc - - hugeParam + - dupImport # https://github.com/go-critic/go-critic/issues/845 + - ifElseChain + - octalLiteral + - whyNoLint + - wrapperFunc + - hugeParam gocyclo: - min-complexity: - 30 # decrease this - # gci: - # local-prefixes: insert your package name here - # goimports: - # local-prefixes: insert your package name here - #revive: - #rules: - #- name: var-naming - #severity: warning + min-complexity: 30 gomnd: settings: mnd: @@ -54,31 +45,31 @@ linters: # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint disable-all: true enable: - - bodyclose - - dogsled - - gocritic - - gofmt - - goimports - - goprintffuncname - - gosimple - - govet - - ineffassign - - lll - - misspell - - nakedret - - rowserrcheck - - staticcheck - - stylecheck - - typecheck - - unconvert - - unparam - - unused - - whitespace - - revive - - dupl - - gocyclo - - gosec - - nolintlint + - bodyclose + - dogsled + - gocritic + - gofmt + - goimports + - goprintffuncname + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - rowserrcheck + - staticcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - whitespace + - revive + - dupl + - gocyclo + - gosec + - nolintlint # don't enable: # - noctx @@ -107,25 +98,28 @@ linters: issues: # Excluding configuration per-path, per-linter, per-text and per-source exclude-rules: - - path: _test\.go - linters: - - gomnd - - gochecknoglobals - - gosec - - noctx - - goerr113 - - goconst - - dupl - - unparam + - path: _test\.go + linters: + - gomnd + - gochecknoglobals + - gosec + - noctx + - goerr113 + - goconst + - dupl + - unparam + + # https://github.com/go-critic/go-critic/issues/926 + - linters: + - gocritic + text: "unnecessaryDefer:" - # https://github.com/go-critic/go-critic/issues/926 - - linters: - - gocritic - text: "unnecessaryDefer:" + - text: "should not use dot imports" + path: _test\.go # silence stupid linter errors exclude: - - directive `// nolint.*` should be written without leading space + - directive `// nolint.*` should be written without leading space run: timeout: 15m diff --git a/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go b/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go index 0e81d9fc..1c1cc8ca 100644 --- a/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go +++ b/controllers/yawol-controller/loadbalancermachine/loadbalancermachine_controller.go @@ -431,7 +431,7 @@ func (r *LoadBalancerMachineReconciler) reconcileRoleBinding( return nil } -func (r *LoadBalancerMachineReconciler) reconcilePort( //nolint: gocyclo // TODO reduce complexity in future +func (r *LoadBalancerMachineReconciler) reconcilePort( // nolint: gocyclo // TODO reduce complexity in future ctx context.Context, osClient os.Client, req ctrl.Request, @@ -441,20 +441,20 @@ func (r *LoadBalancerMachineReconciler) reconcilePort( //nolint: gocyclo // TODO var err error // TODO cleanup after removing deprecated fields - if lbm.Status.PortID != nil && lbm.Status.DefaultPortID == nil { //nolint: staticcheck // needed to be backwards compatible + if lbm.Status.PortID != nil && lbm.Status.DefaultPortID == nil { // nolint: staticcheck // needed to be backwards compatible if err := helper.PatchLBMStatus( ctx, r.Client.Status(), lbm, - yawolv1beta1.LoadBalancerMachineStatus{DefaultPortID: lbm.Status.PortID}, //nolint: staticcheck // needed to be backwards compatible + yawolv1beta1.LoadBalancerMachineStatus{DefaultPortID: lbm.Status.PortID}, // nolint: staticcheck // needed to be backwards compatible ); err != nil { return err } } // TODO cleanup after removing deprecated fields - if lbm.Status.PortID != nil && lbm.Status.DefaultPortID != nil && //nolint: staticcheck // needed to be backwards compatible - *lbm.Status.PortID == *lbm.Status.DefaultPortID { //nolint: staticcheck // needed to be backwards compatible + if lbm.Status.PortID != nil && lbm.Status.DefaultPortID != nil && // nolint: staticcheck // needed to be backwards compatible + *lbm.Status.PortID == *lbm.Status.DefaultPortID { // nolint: staticcheck // needed to be backwards compatible if err := helper.RemoveFromLBMStatus(ctx, r.Client.Status(), lbm, "portID"); err != nil { return err } @@ -462,8 +462,8 @@ func (r *LoadBalancerMachineReconciler) reconcilePort( //nolint: gocyclo // TODO // TODO cleanup after removing deprecated fields var networkID string - if lbm.Spec.Infrastructure.NetworkID != "" { //nolint: staticcheck // needed to be backwards compatible - networkID = lbm.Spec.Infrastructure.NetworkID //nolint: staticcheck // needed to be backwards compatible + if lbm.Spec.Infrastructure.NetworkID != "" { // nolint: staticcheck // needed to be backwards compatible + networkID = lbm.Spec.Infrastructure.NetworkID // nolint: staticcheck // needed to be backwards compatible } if lbm.Spec.Infrastructure.DefaultNetwork.NetworkID != "" { networkID = lbm.Spec.Infrastructure.DefaultNetwork.NetworkID @@ -770,8 +770,8 @@ func (r *LoadBalancerMachineReconciler) createServer( // TODO cleanup after removing deprecated fields var networkID string - if loadBalancerMachine.Spec.Infrastructure.NetworkID != "" { //nolint: staticcheck // needed to be backwards compatible - networkID = loadBalancerMachine.Spec.Infrastructure.NetworkID //nolint: staticcheck // needed to be backwards compatible + if loadBalancerMachine.Spec.Infrastructure.NetworkID != "" { // nolint: staticcheck // needed to be backwards compatible + networkID = loadBalancerMachine.Spec.Infrastructure.NetworkID // nolint: staticcheck // needed to be backwards compatible } if loadBalancerMachine.Spec.Infrastructure.DefaultNetwork.NetworkID != "" { networkID = loadBalancerMachine.Spec.Infrastructure.DefaultNetwork.NetworkID @@ -926,8 +926,8 @@ func (r *LoadBalancerMachineReconciler) deletePort( } // TODO cleanup after removing deprecated fields - if lbm.Status.PortID != nil { //nolint: staticcheck // needed to be backwards compatible - //nolint: staticcheck // needed to be backwards compatible + if lbm.Status.PortID != nil { // nolint: staticcheck // needed to be backwards compatible + // nolint: staticcheck // needed to be backwards compatible if err = openstackhelper.DeletePort(ctx, portClient, *lbm.Status.PortID); err != nil { switch err.(type) { case gophercloud.ErrDefault404: @@ -981,7 +981,7 @@ func (r *LoadBalancerMachineReconciler) deleteSA( Namespace: lbm.Namespace, }, } - if err := r.Client.Delete(ctx, &sa); client.IgnoreNotFound(err) != nil { //nolint: gocritic // ignore of not found is intended + if err := r.Client.Delete(ctx, &sa); client.IgnoreNotFound(err) != nil { // nolint: gocritic // ignore of not found is intended return err } @@ -998,7 +998,7 @@ func (r *LoadBalancerMachineReconciler) deleteRoleBinding( Namespace: lbm.Namespace, }, } - if err := r.Client.Delete(ctx, &rb); client.IgnoreNotFound(err) != nil { //nolint: gocritic // ignore of not found is intended + if err := r.Client.Delete(ctx, &rb); client.IgnoreNotFound(err) != nil { // nolint: gocritic // ignore of not found is intended return err } @@ -1015,7 +1015,7 @@ func (r *LoadBalancerMachineReconciler) deleteRole( Namespace: lbm.Namespace, }, } - if err := r.Client.Delete(ctx, &role); client.IgnoreNotFound(err) != nil { //nolint: gocritic // ignore of not found is intended + if err := r.Client.Delete(ctx, &role); client.IgnoreNotFound(err) != nil { // nolint: gocritic // ignore of not found is intended return err }