Skip to content

Commit

Permalink
Format and improve linter settings
Browse files Browse the repository at this point in the history
  • Loading branch information
timebertt committed Sep 10, 2024
1 parent cb22181 commit 8f49186
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 75 deletions.
116 changes: 55 additions & 61 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -441,29 +441,29 @@ 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
}
}

// 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 8f49186

Please sign in to comment.