diff --git a/.binny.yaml b/.binny.yaml index c0d60d686..f5c7f3494 100644 --- a/.binny.yaml +++ b/.binny.yaml @@ -26,7 +26,7 @@ tools: # used for linting - name: golangci-lint version: - want: v1.64.5 + want: v1.64.6 method: github-release with: repo: golangci/golangci-lint diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index c394b8a5f..2760c7e3b 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -21,7 +21,7 @@ jobs: analyze: name: Analyze runs-on: ubuntu-22.04-4core-16gb - + if: github.repository == 'anchore/syft' # only run for main repo permissions: security-events: write diff --git a/.github/workflows/test-fixture-cache-publish.yaml b/.github/workflows/test-fixture-cache-publish.yaml index 1bc3b8f02..21288ecbc 100644 --- a/.github/workflows/test-fixture-cache-publish.yaml +++ b/.github/workflows/test-fixture-cache-publish.yaml @@ -15,6 +15,7 @@ jobs: name: "Publish test fixture image cache" # we use this runner to get enough storage space for docker images and fixture cache runs-on: ubuntu-22.04-4core-16gb + if: github.repository == 'anchore/syft' # only run for main repo permissions: packages: write steps: diff --git a/.golangci.yaml b/.golangci.yaml index 182cfcdc8..400d739ab 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -62,11 +62,6 @@ linters-settings: excludes: - G115 - staticcheck: - checks: - - all - - -SA4023 - run: timeout: 10m tests: false diff --git a/syft/format/internal/cyclonedxutil/helpers/property_encoder.go b/syft/format/internal/cyclonedxutil/helpers/property_encoder.go index c2daf85de..cfa7e2697 100644 --- a/syft/format/internal/cyclonedxutil/helpers/property_encoder.go +++ b/syft/format/internal/cyclonedxutil/helpers/property_encoder.go @@ -54,7 +54,7 @@ func lowerFirst(s string) string { } // Encode recursively encodes the object's properties as an ordered set of NameValue pairs -func Encode(obj interface{}, prefix string, fn FieldName) map[string]string { +func Encode(obj any, prefix string, fn FieldName) map[string]string { if obj == nil { return nil } @@ -86,7 +86,7 @@ func Sorted(values map[string]string) (out []NameValue) { } func encode(out map[string]string, value reflect.Value, prefix string, fn FieldName) { - if !value.IsValid() || value.Type() == nil { + if !value.IsValid() { return } @@ -156,7 +156,7 @@ func fieldName(f reflect.StructField, prefix string, fn FieldName) (string, bool } // Decode based on the given type, applies all values to hydrate a new instance -func Decode(typ reflect.Type, values map[string]string, prefix string, fn FieldName) interface{} { +func Decode(typ reflect.Type, values map[string]string, prefix string, fn FieldName) any { isPtr := false for typ.Kind() == reflect.Ptr { typ = typ.Elem() @@ -185,7 +185,7 @@ func Decode(typ reflect.Type, values map[string]string, prefix string, fn FieldN } // DecodeInto decodes all values to hydrate the given object instance -func DecodeInto(obj interface{}, values map[string]string, prefix string, fn FieldName) { +func DecodeInto(obj any, values map[string]string, prefix string, fn FieldName) { value := reflect.ValueOf(obj) for value.Type().Kind() == reflect.Ptr { @@ -197,7 +197,7 @@ func DecodeInto(obj interface{}, values map[string]string, prefix string, fn Fie //nolint:funlen,gocognit,gocyclo func decode(vals map[string]string, value reflect.Value, prefix string, fn FieldName) bool { - if !value.IsValid() || value.Type() == nil { + if !value.IsValid() { return false } @@ -361,7 +361,7 @@ func decode(vals map[string]string, value reflect.Value, prefix string, fn Field return true } -func PtrToStruct(ptr interface{}) interface{} { +func PtrToStruct(ptr any) any { v := reflect.ValueOf(ptr) if v.IsZero() && v.Type().Kind() != reflect.Struct { return nil @@ -371,6 +371,10 @@ func PtrToStruct(ptr interface{}) interface{} { return PtrToStruct(v.Elem().Interface()) case reflect.Interface: return PtrToStruct(v.Elem().Interface()) + default: + if v.CanInterface() { + return v.Interface() + } } - return v.Interface() + return nil }