Skip to content

Commit 6ba6129

Browse files
TomCN0803sridharavinashdomdomegg
authored
feat: migrate golangci-lint from v1 to v2 (#144)
Migrate golangci-lint from v1 to v2. ## Motivation and Context The golangci-lint has been upgraded to v2 since March 2025. The v2 of golangci-lint has simplified the linters management. ## How Has This Been Tested? Tested locally with [email protected] ## Breaking Changes No. ## Types of changes - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [x] My code follows the repository's style guidelines - [x] New and existing tests pass locally - [x] I have added appropriate error handling - [ ] I have added or updated documentation as needed ## Additional context <!-- Add any other context, implementation notes, or design decisions --> --------- Co-authored-by: haokunt <[email protected]> Co-authored-by: Avinash Sridhar <[email protected]> Co-authored-by: Adam Jones <[email protected]>
1 parent 502b628 commit 6ba6129

File tree

9 files changed

+94
-101
lines changed

9 files changed

+94
-101
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
- name: Install golangci-lint
2727
run: |
28-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0
28+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.3.1
2929
3030
- name: Run golangci-lint
3131
run: golangci-lint run --timeout=5m

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ build/*
44
.mcpregistry*
55
**/bin
66
cmd/registry/registry
7+
.DS_Store
78
validate-examples
89
validate-schemas
910
.idea/

.golangci.yml

Lines changed: 67 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
# GolangCI-Lint configuration
22
# See: https://golangci-lint.run/usage/configuration/
33

4+
version: "2"
45
run:
5-
timeout: 5m
66
modules-download-mode: readonly
7-
87
linters:
98
enable:
10-
- errcheck
11-
- gosimple
12-
- govet
13-
- ineffassign
14-
- staticcheck
15-
- typecheck
16-
- unused
179
- asasalint
1810
- asciicheck
1911
- bidichk
@@ -28,14 +20,11 @@ linters:
2820
- exhaustive
2921
- forbidigo
3022
- funlen
31-
- gci
3223
- gocognit
3324
- goconst
3425
- gocritic
3526
- gocyclo
3627
- godox
37-
- gofmt
38-
- goimports
3928
- gomoddirectives
4029
- gomodguard
4130
- goprintffuncname
@@ -59,8 +48,7 @@ linters:
5948
- revive
6049
- rowserrcheck
6150
- sqlclosecheck
62-
- stylecheck
63-
- tenv
51+
- staticcheck
6452
- testpackage
6553
- thelper
6654
- tparallel
@@ -69,55 +57,69 @@ linters:
6957
- usestdlibvars
7058
- wastedassign
7159
- whitespace
72-
73-
linters-settings:
74-
revive:
60+
settings:
61+
cyclop:
62+
max-complexity: 50
63+
funlen:
64+
lines: 150
65+
statements: 150
66+
gocognit:
67+
min-complexity: 50
68+
goconst:
69+
min-len: 3
70+
min-occurrences: 3
71+
gocyclo:
72+
min-complexity: 25
73+
lll:
74+
line-length: 150
75+
misspell:
76+
locale: US
77+
mnd:
78+
checks:
79+
- argument
80+
- case
81+
- condition
82+
- operation
83+
- return
84+
nestif:
85+
min-complexity: 8
86+
exclusions:
87+
generated: lax
88+
presets:
89+
- comments
90+
- common-false-positives
91+
- legacy
92+
- std-error-handling
7593
rules:
76-
- name: use-any
77-
disabled: false
78-
severity: error
79-
cyclop:
80-
max-complexity: 50
81-
funlen:
82-
lines: 150
83-
statements: 150
84-
gocognit:
85-
min-complexity: 50
86-
gocyclo:
87-
min-complexity: 25
88-
goconst:
89-
min-len: 3
90-
min-occurrences: 3
91-
mnd:
92-
checks:
93-
- argument
94-
- case
95-
- condition
96-
- operation
97-
- return
98-
lll:
99-
line-length: 150
100-
misspell:
101-
locale: US
102-
nestif:
103-
min-complexity: 8
104-
105-
issues:
106-
exclude-rules:
107-
# Exclude some linters from running on tests files.
108-
- path: _test\.go
109-
linters:
110-
- mnd
111-
- funlen
112-
- gocyclo
113-
- errcheck
114-
- dupl
115-
- gosec
116-
# Ignore long lines in generated code
117-
- path: docs/
118-
linters:
119-
- lll
120-
# Allow local replacement directives in go.mod
121-
- path: go\.mod
122-
linters:
123-
- gomoddirectives
94+
- linters:
95+
- dupl
96+
- errcheck
97+
- funlen
98+
- gocyclo
99+
- gosec
100+
- mnd
101+
path: _test\.go
102+
- linters:
103+
- lll
104+
path: docs/
105+
- linters:
106+
- mnd
107+
path: integrationtests/
108+
- linters:
109+
- gomoddirectives
110+
path: go\.mod
111+
paths:
112+
- third_party$
113+
- builtin$
114+
- examples$
115+
formatters:
116+
enable:
117+
- gci
118+
- gofmt
119+
- goimports
120+
exclusions:
121+
generated: lax
122+
paths:
123+
- third_party$
124+
- builtin$
125+
- examples$

CLAUDE.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ MCP Registry is a community-driven registry service for Model Context Protocol (
1010
### Prerequisites
1111
- **Go 1.23.x** - The project requires this specific version (check with `go version`)
1212
- Consider using a Go version manager like `g` or `gvm` if you work on multiple projects
13-
- **golangci-lint v1.61.0** - Install with:
13+
- **golangci-lint v2.3.1** - Install with:
1414
```bash
15-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0
15+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.3.1
1616
```
1717

1818
### Git Hooks (Optional)
@@ -72,7 +72,7 @@ gofmt -s -l .
7272
gofmt -s -w .
7373
```
7474

75-
**Note**: The project uses golangci-lint v1.61.0 with 62 enabled linters. Always run linting locally before pushing to avoid CI failures.
75+
**Note**: The project uses golangci-lint v2.3.1 with 62 enabled linters. Always run linting locally before pushing to avoid CI failures.
7676

7777
## Architecture Overview
7878

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ The MCP Registry service provides a centralized repository for MCP server entrie
2929
- Docker (optional, but recommended for development)
3030

3131
For development:
32-
- golangci-lint v1.61.0 - Install with:
32+
- golangci-lint v2.3.1 - Install with:
3333
```bash
34-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0
34+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.3.1
3535
```
3636

3737
## Running

internal/api/handlers/v0/publish_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ type MockRegistryService struct {
2323
}
2424

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

3030
func (m *MockRegistryService) GetByID(id string) (*model.ServerDetail, error) {
31-
args := m.Mock.Called(id)
31+
args := m.Called(id)
3232
return args.Get(0).(*model.ServerDetail), args.Error(1)
3333
}
3434

3535
func (m *MockRegistryService) Publish(serverDetail *model.ServerDetail) error {
36-
args := m.Mock.Called(serverDetail)
36+
args := m.Called(serverDetail)
3737
return args.Error(0)
3838
}
3939

@@ -45,17 +45,17 @@ type MockAuthService struct {
4545
func (m *MockAuthService) StartAuthFlow(
4646
ctx context.Context, method model.AuthMethod, repoRef string,
4747
) (map[string]string, string, error) {
48-
args := m.Mock.Called(ctx, method, repoRef)
48+
args := m.Called(ctx, method, repoRef)
4949
return args.Get(0).(map[string]string), args.String(1), args.Error(2)
5050
}
5151

5252
func (m *MockAuthService) CheckAuthStatus(ctx context.Context, statusToken string) (string, error) {
53-
args := m.Mock.Called(ctx, statusToken)
53+
args := m.Called(ctx, statusToken)
5454
return args.String(0), args.Error(1)
5555
}
5656

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

@@ -416,8 +416,8 @@ func TestPublishHandler(t *testing.T) {
416416
}
417417

418418
// Assert that all expectations were met
419-
mockRegistry.Mock.AssertExpectations(t)
420-
mockAuthService.Mock.AssertExpectations(t)
419+
mockRegistry.AssertExpectations(t)
420+
mockAuthService.AssertExpectations(t)
421421
})
422422
}
423423
}
@@ -487,7 +487,7 @@ func TestPublishHandlerBearerTokenParsing(t *testing.T) {
487487
handler.ServeHTTP(rr, req)
488488

489489
assert.Equal(t, http.StatusCreated, rr.Code)
490-
mockAuthService.Mock.AssertExpectations(t)
490+
mockAuthService.AssertExpectations(t)
491491
})
492492
}
493493
}
@@ -552,7 +552,7 @@ func TestPublishHandlerAuthMethodSelection(t *testing.T) {
552552
handler.ServeHTTP(rr, req)
553553

554554
assert.Equal(t, http.StatusCreated, rr.Code)
555-
mockAuthService.Mock.AssertExpectations(t)
555+
mockAuthService.AssertExpectations(t)
556556
})
557557
}
558558
}
@@ -639,9 +639,9 @@ func TestPublishIntegration(t *testing.T) {
639639
// Verify the server was actually published by retrieving it
640640
publishedServer, err := registryService.GetByID(response["id"])
641641
require.NoError(t, err)
642-
assert.Equal(t, publishReq.ServerDetail.Name, publishedServer.Name)
643-
assert.Equal(t, publishReq.ServerDetail.Description, publishedServer.Description)
644-
assert.Equal(t, publishReq.ServerDetail.VersionDetail.Version, publishedServer.VersionDetail.Version)
642+
assert.Equal(t, publishReq.Name, publishedServer.Name)
643+
assert.Equal(t, publishReq.Description, publishedServer.Description)
644+
assert.Equal(t, publishReq.VersionDetail.Version, publishedServer.VersionDetail.Version)
645645
assert.Len(t, publishedServer.Packages, 1)
646646
assert.Len(t, publishedServer.Remotes, 1)
647647
})

internal/api/handlers/v0/servers.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,8 @@ func ServersHandler(registry service.RegistryService) http.HandlerFunc {
6060
return
6161
}
6262

63-
if parsedLimit > 100 {
64-
// Cap maximum limit to prevent excessive queries
65-
limit = 100
66-
} else {
67-
limit = parsedLimit
68-
}
63+
// Cap maximum limit to prevent excessive queries
64+
limit = min(parsedLimit, 100)
6965
}
7066

7167
// Use the GetAll method to get paginated results

internal/api/handlers/v0/servers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func TestServersHandler(t *testing.T) {
257257
}
258258

259259
// Verify mock expectations
260-
mockRegistry.Mock.AssertExpectations(t)
260+
mockRegistry.AssertExpectations(t)
261261
})
262262
}
263263
}
@@ -321,7 +321,7 @@ func TestServersHandlerIntegration(t *testing.T) {
321321
assert.Empty(t, paginatedResp.Metadata.NextCursor)
322322

323323
// Verify mock expectations
324-
mockRegistry.Mock.AssertExpectations(t)
324+
mockRegistry.AssertExpectations(t)
325325
}
326326

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

389389
// Verify mock expectations
390-
mockRegistry.Mock.AssertExpectations(t)
390+
mockRegistry.AssertExpectations(t)
391391
}

internal/database/memory.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ func compareSemanticVersions(version1, version2 string) int {
4848
parts2 := strings.Split(version2, ".")
4949

5050
// Pad with zeros if needed
51-
maxLen := len(parts1)
52-
if len(parts2) > maxLen {
53-
maxLen = len(parts2)
54-
}
51+
maxLen := max(len(parts2), len(parts1))
5552

5653
for len(parts1) < maxLen {
5754
parts1 = append(parts1, "0")
@@ -162,10 +159,7 @@ func (db *MemoryDB) List(
162159
})
163160

164161
// Apply pagination
165-
endIdx := startIdx + limit
166-
if endIdx > len(filteredEntries) {
167-
endIdx = len(filteredEntries)
168-
}
162+
endIdx := min(startIdx+limit, len(filteredEntries))
169163

170164
var result []*model.Server
171165
if startIdx < len(filteredEntries) {

0 commit comments

Comments
 (0)