Skip to content

feat: migrate golangci-lint from v1 to v2 #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

- name: Install golangci-lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.1.6

- name: Run golangci-lint
run: golangci-lint run --timeout=5m
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build/*
.mcpregistry*
**/bin
cmd/registry/registry
.DS_Store
133 changes: 68 additions & 65 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
# GolangCI-Lint configuration
# See: https://golangci-lint.run/usage/configuration/

version: "2"
run:
timeout: 5m
modules-download-mode: readonly

linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
- asasalint
- asciicheck
- bidichk
Expand All @@ -28,14 +20,11 @@ linters:
- exhaustive
- forbidigo
- funlen
- gci
- gocognit
- goconst
- gocritic
- gocyclo
- godox
- gofmt
- goimports
- gomoddirectives
- gomodguard
- goprintffuncname
Expand All @@ -59,8 +48,7 @@ linters:
- revive
- rowserrcheck
- sqlclosecheck
- stylecheck
- tenv
- staticcheck
- testpackage
- thelper
- tparallel
Expand All @@ -69,54 +57,69 @@ linters:
- usestdlibvars
- wastedassign
- whitespace

linters-settings:
cyclop:
max-complexity: 50
funlen:
lines: 150
statements: 150
gocognit:
min-complexity: 50
gocyclo:
min-complexity: 25
goconst:
min-len: 3
min-occurrences: 3
mnd:
checks:
- argument
- case
- condition
- operation
- return
lll:
line-length: 150
misspell:
locale: US
nestif:
min-complexity: 8

issues:
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- mnd
- funlen
- gocyclo
- errcheck
- dupl
- gosec
# Ignore long lines in generated code
- path: docs/
linters:
- lll
# Ignore magic numbers in test files
- path: integrationtests/
linters:
- mnd
# Allow local replacement directives in go.mod
- path: go\.mod
linters:
- gomoddirectives
settings:
cyclop:
max-complexity: 50
funlen:
lines: 150
statements: 150
gocognit:
min-complexity: 50
goconst:
min-len: 3
min-occurrences: 3
gocyclo:
min-complexity: 25
lll:
line-length: 150
misspell:
locale: US
mnd:
checks:
- argument
- case
- condition
- operation
- return
nestif:
min-complexity: 8
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- dupl
- errcheck
- funlen
- gocyclo
- gosec
- mnd
path: _test\.go
- linters:
- lll
path: docs/
- linters:
- mnd
path: integrationtests/
- linters:
- gomoddirectives
path: go\.mod
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gci
- gofmt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
6 changes: 3 additions & 3 deletions integrationtests/publish_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ func TestPublishIntegration(t *testing.T) {
// Verify the server was actually published by retrieving it
publishedServer, err := registryService.GetByID(response["id"])
require.NoError(t, err)
assert.Equal(t, publishReq.ServerDetail.Name, publishedServer.Name)
assert.Equal(t, publishReq.ServerDetail.Description, publishedServer.Description)
assert.Equal(t, publishReq.ServerDetail.VersionDetail.Version, publishedServer.VersionDetail.Version)
assert.Equal(t, publishReq.Name, publishedServer.Name)
assert.Equal(t, publishReq.Description, publishedServer.Description)
assert.Equal(t, publishReq.VersionDetail.Version, publishedServer.VersionDetail.Version)
assert.Len(t, publishedServer.Packages, 1)
assert.Len(t, publishedServer.Remotes, 1)
})
Expand Down
6 changes: 3 additions & 3 deletions internal/api/handlers/v0/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func StartAuthHandler(authService auth.Service) http.HandlerFunc {
// Return successful response
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(map[string]interface{}{
if err := json.NewEncoder(w).Encode(map[string]any{
"flow_info": flowInfo,
"status_token": statusToken,
"expires_in": 300, // 5 minutes
Expand Down Expand Up @@ -98,7 +98,7 @@ func CheckAuthStatusHandler(authService auth.Service) http.HandlerFunc {
// Auth is still pending
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(map[string]interface{}{
if err := json.NewEncoder(w).Encode(map[string]any{
"status": "pending",
}); err != nil {
http.Error(w, "Failed to encode response", http.StatusInternalServerError)
Expand All @@ -115,7 +115,7 @@ func CheckAuthStatusHandler(authService auth.Service) http.HandlerFunc {
// Authentication completed successfully
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
if err := json.NewEncoder(w).Encode(map[string]interface{}{
if err := json.NewEncoder(w).Encode(map[string]any{
"status": "complete",
"token": token,
}); err != nil {
Expand Down
22 changes: 11 additions & 11 deletions internal/api/handlers/v0/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ type MockRegistryService struct {
}

func (m *MockRegistryService) List(cursor string, limit int) ([]model.Server, string, error) {
args := m.Mock.Called(cursor, limit)
args := m.Called(cursor, limit)
return args.Get(0).([]model.Server), args.String(1), args.Error(2)
}

func (m *MockRegistryService) GetByID(id string) (*model.ServerDetail, error) {
args := m.Mock.Called(id)
args := m.Called(id)
return args.Get(0).(*model.ServerDetail), args.Error(1)
}

func (m *MockRegistryService) Publish(serverDetail *model.ServerDetail) error {
args := m.Mock.Called(serverDetail)
args := m.Called(serverDetail)
return args.Error(0)
}

Expand All @@ -43,25 +43,25 @@ type MockAuthService struct {
func (m *MockAuthService) StartAuthFlow(
ctx context.Context, method model.AuthMethod, repoRef string,
) (map[string]string, string, error) {
args := m.Mock.Called(ctx, method, repoRef)
args := m.Called(ctx, method, repoRef)
return args.Get(0).(map[string]string), args.String(1), args.Error(2)
}

func (m *MockAuthService) CheckAuthStatus(ctx context.Context, statusToken string) (string, error) {
args := m.Mock.Called(ctx, statusToken)
args := m.Called(ctx, statusToken)
return args.String(0), args.Error(1)
}

func (m *MockAuthService) ValidateAuth(ctx context.Context, authentication model.Authentication) (bool, error) {
args := m.Mock.Called(ctx, authentication)
args := m.Called(ctx, authentication)
return args.Bool(0), args.Error(1)
}

func TestPublishHandler(t *testing.T) {
testCases := []struct {
name string
method string
requestBody interface{}
requestBody any
authHeader string
setupMocks func(*MockRegistryService, *MockAuthService)
expectedStatus int
Expand Down Expand Up @@ -414,8 +414,8 @@ func TestPublishHandler(t *testing.T) {
}

// Assert that all expectations were met
mockRegistry.Mock.AssertExpectations(t)
mockAuthService.Mock.AssertExpectations(t)
mockRegistry.AssertExpectations(t)
mockAuthService.AssertExpectations(t)
})
}
}
Expand Down Expand Up @@ -485,7 +485,7 @@ func TestPublishHandlerBearerTokenParsing(t *testing.T) {
handler.ServeHTTP(rr, req)

assert.Equal(t, http.StatusCreated, rr.Code)
mockAuthService.Mock.AssertExpectations(t)
mockAuthService.AssertExpectations(t)
})
}
}
Expand Down Expand Up @@ -550,7 +550,7 @@ func TestPublishHandlerAuthMethodSelection(t *testing.T) {
handler.ServeHTTP(rr, req)

assert.Equal(t, http.StatusCreated, rr.Code)
mockAuthService.Mock.AssertExpectations(t)
mockAuthService.AssertExpectations(t)
})
}
}
8 changes: 2 additions & 6 deletions internal/api/handlers/v0/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,8 @@ func ServersHandler(registry service.RegistryService) http.HandlerFunc {
return
}

if parsedLimit > 100 {
// Cap maximum limit to prevent excessive queries
limit = 100
} else {
limit = parsedLimit
}
// Cap maximum limit to prevent excessive queries
limit = min(parsedLimit, 100)
}

// Use the GetAll method to get paginated results
Expand Down
6 changes: 3 additions & 3 deletions internal/api/handlers/v0/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func TestServersHandler(t *testing.T) {
}

// Verify mock expectations
mockRegistry.Mock.AssertExpectations(t)
mockRegistry.AssertExpectations(t)
})
}
}
Expand Down Expand Up @@ -321,7 +321,7 @@ func TestServersHandlerIntegration(t *testing.T) {
assert.Empty(t, paginatedResp.Metadata.NextCursor)

// Verify mock expectations
mockRegistry.Mock.AssertExpectations(t)
mockRegistry.AssertExpectations(t)
}

// TestServersDetailHandlerIntegration tests the servers detail handler with actual HTTP requests
Expand Down Expand Up @@ -387,5 +387,5 @@ func TestServersDetailHandlerIntegration(t *testing.T) {
assert.Equal(t, *serverDetail, serverDetailResp)

// Verify mock expectations
mockRegistry.Mock.AssertExpectations(t)
mockRegistry.AssertExpectations(t)
}
2 changes: 1 addition & 1 deletion internal/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
// Database defines the interface for database operations on MCPRegistry entries
type Database interface {
// List retrieves all MCPRegistry entries with optional filtering
List(ctx context.Context, filter map[string]interface{}, cursor string, limit int) ([]*model.Server, string, error)
List(ctx context.Context, filter map[string]any, cursor string, limit int) ([]*model.Server, string, error)
// GetByID retrieves a single ServerDetail by it's ID
GetByID(ctx context.Context, id string) (*model.ServerDetail, error)
// Publish adds a new ServerDetail to the database
Expand Down
2 changes: 1 addition & 1 deletion internal/database/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func ReadSeedFile(path string) ([]model.ServerDetail, error) {
var servers []model.ServerDetail
if err := json.Unmarshal(fileContent, &servers); err != nil {
// Try parsing as a raw JSON array and then convert to our model
var rawData []map[string]interface{}
var rawData []map[string]any
if jsonErr := json.Unmarshal(fileContent, &rawData); jsonErr != nil {
return nil, fmt.Errorf("failed to parse JSON: %w (original error: %w)", jsonErr, err)
}
Expand Down
12 changes: 3 additions & 9 deletions internal/database/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ func compareSemanticVersions(version1, version2 string) int {
parts2 := strings.Split(version2, ".")

// Pad with zeros if needed
maxLen := len(parts1)
if len(parts2) > maxLen {
maxLen = len(parts2)
}
maxLen := max(len(parts2), len(parts1))

for len(parts1) < maxLen {
parts1 = append(parts1, "0")
Expand Down Expand Up @@ -90,7 +87,7 @@ func compareSemanticVersions(version1, version2 string) int {
//gocognit:ignore
func (db *MemoryDB) List(
ctx context.Context,
filter map[string]interface{},
filter map[string]any,
cursor string,
limit int,
) ([]*model.Server, string, error) {
Expand Down Expand Up @@ -162,10 +159,7 @@ func (db *MemoryDB) List(
})

// Apply pagination
endIdx := startIdx + limit
if endIdx > len(filteredEntries) {
endIdx = len(filteredEntries)
}
endIdx := min(startIdx+limit, len(filteredEntries))

var result []*model.Server
if startIdx < len(filteredEntries) {
Expand Down
Loading
Loading