chore: lint-fix

Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
This commit is contained in:
Christopher Phillips 2025-10-14 03:59:42 -04:00
parent 3f117a3eb5
commit 746f00ad68
No known key found for this signature in database
16 changed files with 33 additions and 28 deletions

View File

@ -5,8 +5,9 @@ import (
"os"
"strings"
"github.com/anchore/syft/internal/packagemetadata"
"github.com/dave/jennifer/jen"
"github.com/anchore/syft/internal/packagemetadata"
)
// This program is invoked from syft/internal and generates packagemetadata/generated.go

View File

@ -4,8 +4,9 @@ import (
"fmt"
"os"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/dave/jennifer/jen"
"github.com/anchore/syft/internal/sourcemetadata"
)
// This program is invoked from syft/internal and generates sourcemetadata/generated.go

View File

@ -3,6 +3,7 @@ package task
import (
"github.com/anchore/syft/syft/cataloging/pkgcataloging"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/pkg/cataloger/aiartifact"
"github.com/anchore/syft/syft/pkg/cataloger/alpine"
"github.com/anchore/syft/syft/pkg/cataloger/arch"
"github.com/anchore/syft/syft/pkg/cataloger/binary"
@ -37,7 +38,6 @@ import (
"github.com/anchore/syft/syft/pkg/cataloger/swipl"
"github.com/anchore/syft/syft/pkg/cataloger/terraform"
"github.com/anchore/syft/syft/pkg/cataloger/wordpress"
"github.com/anchore/syft/syft/pkg/cataloger/aiartifact"
)
const (

View File

@ -7,7 +7,6 @@ import (
"strings"
"testing"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/spdx/tools-golang/spdx"
@ -16,6 +15,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/anchore/syft/internal/relationship"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/anchore/syft/syft/artifact"
"github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/format/internal/spdxutil/helpers"

View File

@ -3,12 +3,12 @@ package model
import (
"testing"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/assert"
"github.com/anchore/packageurl-go"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/linux"
"github.com/anchore/syft/syft/pkg"

View File

@ -6,9 +6,9 @@ import (
"strings"
"github.com/CycloneDX/cyclonedx-go"
"github.com/anchore/syft/internal/packagemetadata"
"github.com/anchore/packageurl-go"
"github.com/anchore/syft/internal/packagemetadata"
"github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/format/internal"
"github.com/anchore/syft/syft/pkg"
@ -40,9 +40,10 @@ func EncodeComponent(p pkg.Package, supplier string, locationSorter func(a, b fi
}
componentType := cyclonedx.ComponentTypeLibrary
if p.Type == pkg.BinaryPkg {
switch p.Type {
case pkg.BinaryPkg:
componentType = cyclonedx.ComponentTypeApplication
} else if p.Type == pkg.ModelPkg {
case pkg.ModelPkg:
componentType = cyclonedx.ComponentTypeMachineLearningModel
}

View File

@ -5,9 +5,9 @@ import (
"strings"
"testing"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/stretchr/testify/assert"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/anchore/syft/syft/source"
)

View File

@ -5,9 +5,9 @@ import (
"strings"
"testing"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/stretchr/testify/assert"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/anchore/syft/syft/sbom"
"github.com/anchore/syft/syft/source"
)

View File

@ -3,9 +3,9 @@ package helpers
import (
"testing"
"github.com/anchore/syft/internal/packagemetadata"
"github.com/stretchr/testify/assert"
"github.com/anchore/syft/internal/packagemetadata"
"github.com/anchore/syft/syft/pkg"
)

View File

@ -4,11 +4,11 @@ import (
"encoding/json"
"testing"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/source"
)

View File

@ -6,9 +6,10 @@ import (
"path/filepath"
"testing"
"github.com/anchore/syft/internal/packagemetadata"
"github.com/iancoleman/strcase"
"github.com/stretchr/testify/require"
"github.com/anchore/syft/internal/packagemetadata"
)
type schema struct {

View File

@ -4,13 +4,13 @@ import (
"encoding/json"
"testing"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
stereoscopeFile "github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/format/syftjson/model"
"github.com/anchore/syft/syft/pkg"

View File

@ -7,11 +7,11 @@ import (
"os"
"testing"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
stereoFile "github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/anchore/syft/syft/artifact"
"github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/format/syftjson/model"

View File

@ -3,10 +3,10 @@ package syft
import (
"testing"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/stretchr/testify/require"
"github.com/anchore/stereoscope/pkg/image"
"github.com/anchore/syft/internal/sourcemetadata"
"github.com/anchore/syft/syft/source"
"github.com/anchore/syft/syft/source/sourceproviders"
)

View File

@ -41,7 +41,9 @@ const (
ggufTypeArray = 12
)
// parseGGUFHeader parses the header of a GGUF file from raw bytes and extracts metadata
const unkownGGUFData = "unknown"
//nolint:funlen
func parseGGUFHeader(data []byte, location string) (*pkg.GGUFFileMetadata, error) {
reader := bytes.NewReader(data)
// Read magic number
@ -83,7 +85,7 @@ func parseGGUFHeader(data []byte, location string) (*pkg.GGUFFileMetadata, error
}
// Parse metadata key-value pairs
kvMap := make(map[string]interface{})
kvMap := make(map[string]any)
truncated := false
for i := uint64(0); i < kvCount; i++ {
@ -133,7 +135,7 @@ func parseGGUFHeader(data []byte, location string) (*pkg.GGUFFileMetadata, error
metadata.ModelVersion = version
delete(kvMap, "general.version")
} else {
metadata.ModelVersion = "unknown"
metadata.ModelVersion = unkownGGUFData
}
// Extract parameters count if present
@ -151,7 +153,7 @@ func parseGGUFHeader(data []byte, location string) (*pkg.GGUFFileMetadata, error
metadata.Quantization = inferQuantizationFromFilename(location)
// Note: we keep general.quantized_by in Header since it's not directly mapped to a field
} else {
metadata.Quantization = "unknown"
metadata.Quantization = unkownGGUFData
}
// Compute hash of metadata for stable identifier
@ -194,8 +196,8 @@ func readKVPair(reader io.Reader) (string, interface{}, error) {
return key, value, nil
}
// readValue reads a value based on its type
func readValue(reader io.Reader, valueType uint32) (interface{}, error) {
//nolint:funlen
func readValue(reader io.Reader, valueType uint32) (any, error) {
switch valueType {
case ggufTypeUint8:
var v uint8
@ -308,7 +310,7 @@ func inferQuantizationFromFilename(filename string) string {
if match := quantPattern.FindString(filename); match != "" {
return match
}
return "unknown"
return unkownGGUFData
}
// computeMetadataHash computes a stable hash of the metadata for use as a global identifier
@ -341,4 +343,3 @@ func computeMetadataHash(metadata *pkg.GGUFFileMetadata) string {
hash := sha256.Sum256(jsonBytes)
return fmt.Sprintf("%x", hash[:8]) // Use first 8 bytes (16 hex chars)
}

View File

@ -16,7 +16,7 @@ import (
// parseGGUFModel parses a GGUF model file and returns the discovered package.
func parseGGUFModel(_ context.Context, _ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
defer internal.CloseAndLogError(reader, reader.Location.Path())
defer internal.CloseAndLogError(reader, reader.Path())
// Read header (we'll read a reasonable amount to parse the header without reading entire file)
// GGUF headers are typically < 1MB, but we'll use a 10MB limit to be safe
@ -39,7 +39,7 @@ func parseGGUFModel(_ context.Context, _ file.Resolver, _ *generic.Environment,
}
// Stop if we've read enough for a reasonable header
if len(headerData) > maxHeaderSize {
log.Warnf("GGUF header at %s exceeds max size, truncating", reader.Location.Path())
log.Warnf("GGUF header at %s exceeds max size, truncating", reader.Path())
break
}
}
@ -50,7 +50,7 @@ func parseGGUFModel(_ context.Context, _ file.Resolver, _ *generic.Environment,
}
// Parse the GGUF header
metadata, err := parseGGUFHeader(headerData, reader.Location.Path())
metadata, err := parseGGUFHeader(headerData, reader.Path())
if err != nil {
return nil, nil, fmt.Errorf("failed to parse GGUF file: %w", err)
}
@ -58,7 +58,7 @@ func parseGGUFModel(_ context.Context, _ file.Resolver, _ *generic.Environment,
// Create package from metadata
p := newGGUFPackage(
metadata,
reader.Location.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
reader.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
)
return []pkg.Package{p}, nil, unknown.IfEmptyf([]pkg.Package{p}, "unable to parse GGUF file")