Skip to content

Commit 79d7ac6

Browse files
committed
fix: resolve linter issues in registry package
- Remove unused method receivers in loader.go and schema_validation.go - Simplify redundant if-return pattern in ValidateComplete method - All linter issues resolved, tests still passing
1 parent 74c79c1 commit 79d7ac6

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

pkg/registry/loader.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (l *Loader) LoadAll() error {
6464
if _, err := os.Stat(specPath); err == nil {
6565
// Use directory name as the entry name
6666
entryName := info.Name()
67-
67+
6868
entry, err := l.LoadEntryWithName(specPath, entryName)
6969
if err != nil {
7070
return fmt.Errorf("failed to load %s: %w", specPath, err)
@@ -119,10 +119,10 @@ func (l *Loader) LoadEntryWithName(path string, name string) (*types.RegistryEnt
119119
}
120120

121121
// validateEntry validates a registry entry using comprehensive schema-based validation
122-
func (l *Loader) validateEntry(entry *types.RegistryEntry, name string) error {
122+
func (*Loader) validateEntry(entry *types.RegistryEntry, name string) error {
123123
// Use the new schema validator for comprehensive validation
124124
validator := NewSchemaValidator()
125-
125+
126126
return validator.ValidateComplete(entry, name)
127127
}
128128

@@ -335,7 +335,7 @@ func (b *Builder) ValidateAgainstSchema() error {
335335

336336
// Use the comprehensive schema validator
337337
validator := NewSchemaValidator()
338-
338+
339339
if err := validator.ValidateRegistry(registry); err != nil {
340340
return fmt.Errorf("registry validation failed: %w", err)
341341
}

pkg/registry/loader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55
"path/filepath"
66
"testing"
77

8+
toolhiveRegistry "github.com/stacklok/toolhive/pkg/registry"
89
"github.com/stretchr/testify/assert"
910
"github.com/stretchr/testify/require"
1011

11-
toolhiveRegistry "github.com/stacklok/toolhive/pkg/registry"
1212
"github.com/stacklok/toolhive-registry/pkg/types"
1313
)
1414

pkg/registry/schema_validation.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77

88
toolhiveRegistry "github.com/stacklok/toolhive/pkg/registry"
9+
910
"github.com/stacklok/toolhive-registry/pkg/types"
1011
)
1112

@@ -40,7 +41,7 @@ func (v *SchemaValidator) ValidateEntry(entry *types.RegistryEntry, name string)
4041
}
4142

4243
// ValidateRegistry validates a complete registry using the toolhive schema
43-
func (v *SchemaValidator) ValidateRegistry(registry *toolhiveRegistry.Registry) error {
44+
func (*SchemaValidator) ValidateRegistry(registry *toolhiveRegistry.Registry) error {
4445
// Serialize to JSON for schema validation
4546
registryJSON, err := json.Marshal(registry)
4647
if err != nil {
@@ -56,11 +57,11 @@ func (v *SchemaValidator) ValidateRegistry(registry *toolhiveRegistry.Registry)
5657
}
5758

5859
// convertToToolhiveRegistry converts our RegistryEntry to a minimal toolhive Registry for validation
59-
func (v *SchemaValidator) convertToToolhiveRegistry(entry *types.RegistryEntry, name string) (*toolhiveRegistry.Registry, error) {
60+
func (*SchemaValidator) convertToToolhiveRegistry(entry *types.RegistryEntry, name string) (*toolhiveRegistry.Registry, error) {
6061
registry := &toolhiveRegistry.Registry{
61-
Version: "1.0.0",
62-
LastUpdated: "2024-01-01T00:00:00Z", // Placeholder for validation
63-
Servers: make(map[string]*toolhiveRegistry.ImageMetadata),
62+
Version: "1.0.0",
63+
LastUpdated: "2024-01-01T00:00:00Z", // Placeholder for validation
64+
Servers: make(map[string]*toolhiveRegistry.ImageMetadata),
6465
RemoteServers: make(map[string]*toolhiveRegistry.RemoteServerMetadata),
6566
}
6667

@@ -84,7 +85,7 @@ func (v *SchemaValidator) convertToToolhiveRegistry(entry *types.RegistryEntry,
8485
}
8586

8687
// ValidateEntryFields performs additional field-level validation beyond schema validation
87-
func (v *SchemaValidator) ValidateEntryFields(entry *types.RegistryEntry, name string) error {
88+
func (*SchemaValidator) ValidateEntryFields(entry *types.RegistryEntry, name string) error {
8889
// Basic type validation
8990
if entry.ImageMetadata == nil && entry.RemoteServerMetadata == nil {
9091
return fmt.Errorf("entry '%s' must be either an image or remote server", name)
@@ -106,7 +107,7 @@ func (v *SchemaValidator) ValidateEntryFields(entry *types.RegistryEntry, name s
106107
if entry.URL == "" {
107108
return fmt.Errorf("entry '%s': url field is required for remote servers", name)
108109
}
109-
110+
110111
// Remote servers cannot use stdio transport
111112
if entry.GetTransport() == "stdio" {
112113
return fmt.Errorf("entry '%s': remote servers cannot use stdio transport (use sse or streamable-http)", name)
@@ -137,9 +138,5 @@ func (v *SchemaValidator) ValidateComplete(entry *types.RegistryEntry, name stri
137138
}
138139

139140
// Then perform schema validation
140-
if err := v.ValidateEntry(entry, name); err != nil {
141-
return err
142-
}
143-
144-
return nil
145-
}
141+
return v.ValidateEntry(entry, name)
142+
}

0 commit comments

Comments
 (0)