From c31c175e02f561a66b3107cacd546405df995b96 Mon Sep 17 00:00:00 2001 From: Andreas Fritzler Date: Tue, 1 Oct 2024 13:03:01 +0200 Subject: [PATCH] Fix linting issues --- .golangci.yaml | 26 ----------- .golangci.yml | 61 ++++++++++++++++++++++++++ .reuse/dep5 | 2 +- clientutils/clientutils.go | 3 +- conditionutils/conditionutils.go | 2 +- metautils/metautils.go | 7 ++- modutils/modutils.go | 1 - unstructuredutils/unstructuredutils.go | 3 +- 8 files changed, 68 insertions(+), 37 deletions(-) delete mode 100644 .golangci.yaml create mode 100644 .golangci.yml diff --git a/.golangci.yaml b/.golangci.yaml deleted file mode 100644 index d8c320c..0000000 --- a/.golangci.yaml +++ /dev/null @@ -1,26 +0,0 @@ -run: - concurrency: 4 - timeout: 10m - -linters: - enable: - - revive - - ineffassign - - misspell - - goimports - - importas - - unused - - ginkgolinter - -severity: - default-severity: error - -linters-settings: - revive: - severity: error - rules: - - name: exported - arguments: - - disableStutteringCheck - - name: if-return - disabled: true diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..4d143cb --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,61 @@ +run: + timeout: 10m + allow-parallel-runners: true + +issues: + # don't skip warning about doc comments + # don't exclude the default set of lint + exclude-use-default: false + # restore some of the defaults + # (fill in the rest as needed) + exclude-rules: + - path: "clientutils/*" + linters: + - lll + - path: "envtestutils/*" + linters: + - lll + - path: "unstructuredutils/*" + linters: + - lll + - path: "metautils/*" + linters: + - lll + - path: "kustomizeutils/*" + linters: + - lll + - path: "configutils/*" + linters: + - lll + - path: "conditionutils/*" + linters: + - lll + - path: "testutils/*" + linters: + - lll + - path: "cmdutils/*" + linters: + - dupl +linters: + disable-all: true + enable: + - copyloopvar + - dupl + - errcheck + - goconst + - gocyclo + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - ginkgolinter + - lll + - misspell + - nakedret + - prealloc + - staticcheck + - typecheck + - unconvert + - unparam + - unused \ No newline at end of file diff --git a/.reuse/dep5 b/.reuse/dep5 index 01cc9ea..d47f051 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -9,7 +9,7 @@ Source: https://github.com/ironcore-dev/controller-utils Files: .github/* .gitignore - .golangci.yaml + .golangci.yml CODEOWNERS CODE_OF_CONDUCT.md CONTRIBUTING.md diff --git a/clientutils/clientutils.go b/clientutils/clientutils.go index 44c0cc2..2d1c357 100644 --- a/clientutils/clientutils.go +++ b/clientutils/clientutils.go @@ -488,10 +488,9 @@ func CreateOrUseAndPatch( var ( base = obj.DeepCopyObject().(client.Object) best client.Object - other []client.Object + other = make([]client.Object, 0, len(objects)) ) for _, object := range objects { - object := object if err := setObject(obj, object); err != nil { return controllerutil.OperationResultNone, nil, err } diff --git a/conditionutils/conditionutils.go b/conditionutils/conditionutils.go index f1000d0..eda95cd 100644 --- a/conditionutils/conditionutils.go +++ b/conditionutils/conditionutils.go @@ -116,7 +116,7 @@ func getAndConvertField(v reflect.Value, name string, into interface{}) error { // Otherwise, it returns a pointer to that value. func direct(v reflect.Value) reflect.Value { if v.IsZero() { - return reflect.New(reflect.PtrTo(v.Type())).Elem() + return reflect.New(reflect.PointerTo(v.Type())).Elem() } res := reflect.New(v.Type()) diff --git a/metautils/metautils.go b/metautils/metautils.go index 333ca50..a7bd56f 100644 --- a/metautils/metautils.go +++ b/metautils/metautils.go @@ -28,14 +28,13 @@ func ConvertAndSetList(scheme *runtime.Scheme, list runtime.Object, objs []runti return err } - var converted []runtime.Object - for _, obj := range objs { + converted := make([]runtime.Object, len(objs)) + for i, obj := range objs { into := reflect.New(elemType).Interface() if err := scheme.Convert(obj, into, nil); err != nil { return err } - - converted = append(converted, into.(runtime.Object)) + converted[i] = into.(runtime.Object) } return meta.SetList(list, converted) } diff --git a/modutils/modutils.go b/modutils/modutils.go index 5d0bbf8..a851b7b 100644 --- a/modutils/modutils.go +++ b/modutils/modutils.go @@ -99,7 +99,6 @@ func (e *Executor) GetE(name string) (*Module, error) { continue } - mod := mod return &mod, nil } return nil, fmt.Errorf("module %q not found", name) diff --git a/unstructuredutils/unstructuredutils.go b/unstructuredutils/unstructuredutils.go index 06f4e13..d9d3df0 100644 --- a/unstructuredutils/unstructuredutils.go +++ b/unstructuredutils/unstructuredutils.go @@ -63,7 +63,7 @@ func Read(r io.Reader) ([]unstructured.Unstructured, error) { for { ext := runtime.RawExtension{} if err := d.Decode(&ext); err != nil { - if !errors.Is(io.EOF, err) { + if !errors.Is(err, io.EOF) { return nil, fmt.Errorf("error parsing: %w", err) } return objs, nil @@ -107,7 +107,6 @@ func UnstructuredSliceToObjectSlice(unstructureds []unstructured.Unstructured) [ } res := make([]client.Object, 0, len(unstructureds)) for _, u := range unstructureds { - u := u res = append(res, &u) } return res