Skip to content

Commit 466f36b

Browse files
authored
golangci-lint: updates (#114)
- Add golangci-lint configuration with core linters (errcheck, govet, staticcheck, unused), and formatters (gci, gofmt, goimports, golines) with 120 char line limit. - Add detailed golangci-lint instructions to CONTRIBUTING.md - Add Requirements section with gofumpt and golangci-lint links - Update GitHub Actions to use golangci-lint v2.3.0 - Separate linting and testing steps in contribution workflow - Apply fixes from linting - Standarize on camelCase for JSON properties (breaking change!) - Added exceptions for upstream JSON data
1 parent ee8e1d2 commit 466f36b

File tree

24 files changed

+239
-81
lines changed

24 files changed

+239
-81
lines changed

.github/workflows/golangci-lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ jobs:
2727
- name: golangci-lint
2828
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # 8.0.0
2929
with:
30-
version: v2.1
30+
version: v2.3.0

.golangci.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
version: "2"
2+
3+
linters:
4+
enable:
5+
- errcheck
6+
- govet
7+
- ineffassign
8+
- staticcheck
9+
- unused
10+
- tagliatelle
11+
- tagalign
12+
settings:
13+
tagliatelle:
14+
case:
15+
rules:
16+
json: camel
17+
yaml: snake
18+
toml: snake
19+
overrides:
20+
# Ignore the _meta field on 'Tool'
21+
- pkg: internal/packages
22+
ignored-fields:
23+
- Meta
24+
# Ignore casing conflicts in upstream data
25+
- pkg: internal/provider/mcpm
26+
ignore: true
27+
28+
formatters:
29+
enable:
30+
- gci
31+
- gofmt
32+
- gofumpt
33+
- goimports
34+
- golines
35+
settings:
36+
gci:
37+
# Section configuration to compare against.
38+
# Section names are case-insensitive and may contain parameters in ().
39+
# The default order of sections is `standard > default > custom > blank > dot > alias > localmodule`.
40+
# If `custom-order` is `true`, it follows the order of `sections` option.
41+
# Default: ["standard", "default"]
42+
sections:
43+
- standard # Standard section: captures all standard packages.
44+
- default # Default section: contains all imports that could not be matched to another section type.
45+
- prefix(github.com/mozilla-ai/mcpd) # Custom section: groups all imports with the specified Prefix.
46+
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
47+
- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
48+
#- alias # Alias section: contains all alias imports. This section is not present unless explicitly enabled.
49+
- localmodule # Local module section: contains all local packages. This section is not present unless explicitly enabled.
50+
golines:
51+
max-len: 120
52+
53+
issues:
54+
fix: true
55+
56+
output:
57+
formats:
58+
text:
59+
# Default: stdout
60+
path: stderr
61+
sort-order:
62+
- severity
63+
- file
64+
- linter
65+
66+
run:
67+
timeout: 5m
68+
# The mode used to evaluate relative paths.
69+
# It's used by exclusions, Go plugins, and some linters.
70+
# The value can be:
71+
# - `gomod`: the paths will be relative to the directory of the `go.mod` file.
72+
# - `gitroot`: the paths will be relative to the git root (the parent directory of `.git`).
73+
# - `cfg`: the paths will be relative to the configuration file.
74+
# - `wd` (NOT recommended): the paths will be relative to the place where golangci-lint is run.
75+
# Default: cfg
76+
relative-path-mode: gomod
77+
modules-download-mode: readonly
78+
allow-parallel-runners: true
79+
allow-serial-runners: true

CONTRIBUTING.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,44 @@ We encourage contributions via GitHub pull requests. Before you start, please re
1515
* **Features:** Please use our [Feature Request template](.github/ISSUE_TEMPLATE/feature_request.yaml) to describe the problem your idea solves and your proposed solution.
1616
* **Search First:** Before creating a new issue, please search existing issues to see if your topic has already been discussed.
1717

18+
### Requirements
19+
20+
* [gofumpt](https://github.com/mvdan/gofumpt)
21+
* [golangci-lint](https://golangci-lint.run/welcome/install/)
22+
1823
### Contributing Code
1924

2025
1. **Fork** the repository on GitHub.
21-
1. **Clone** your forked repository to your local machine.
26+
2. **Clone** your forked repository to your local machine.
2227
```bash
2328
git clone https://github.com/{YOUR_GITHUB_USERNAME}/mcpd.git
2429
cd mcpd
2530
```
26-
1. **Create a new branch** for your changes based on the `main` branch.
31+
3. **Create a new branch** for your changes based on the `main` branch.
2732
```bash
2833
git checkout main
2934
git pull origin main
3035
git checkout -b your-feature-or-bugfix-branch
3136
```
32-
1. **Make your changes.**
33-
1. **Format and Lint:** Ensure your code is formatted using [gofumpt](https://github.com/mvdan/gofumpt) and [golangci-lint run ./...](https://golangci-lint.run/welcome/install/).
34-
1. **Add Unit Tests:** All new features and bug fixes should be accompanied by relevant unit tests.
35-
1. **Commit your changes** with a clear and descriptive message.
36-
1. **Push your branch** to your forked repository.
37-
1. **Open a Pull Request** from your branch to the `main` branch of the upstream `mozilla-ai/mcpd` repository,
37+
4. **Make your changes:** You can build your changes with:
38+
```bash
39+
make build
40+
```
41+
5. **Format and Lint:** Ensure your code passes linting and formatting checks:
42+
```bash
43+
# Run golangci-lint (uses .golangci.yaml config)
44+
golangci-lint run
45+
46+
# Auto-fix formatting issues (recommended)
47+
golangci-lint run --fix
48+
```
49+
6. **Add Unit Tests:** All new features and bug fixes should be accompanied by relevant unit tests. Run tests with:
50+
```bash
51+
make test
52+
```
53+
7. **Commit your changes** with a clear and descriptive message.
54+
8. **Push your branch** to your forked repository.
55+
9. **Open a Pull Request** from your branch to the `main` branch of the upstream `mozilla-ai/mcpd` repository,
3856
reference the relevant GitHub issue in your PR summary.
3957

4058
## Security Vulnerabilities

cmd/add.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,10 @@ func parseServerEntry(
231231

232232
runtimeSpecificName := pkg.InstallationDetails[selectedRuntime].Package
233233
if runtimeSpecificName == "" {
234-
return config.ServerEntry{}, fmt.Errorf("installation package name is missing for runtime '%s'", selectedRuntime)
234+
return config.ServerEntry{}, fmt.Errorf(
235+
"installation package name is missing for runtime '%s'",
236+
selectedRuntime,
237+
)
235238
}
236239
runtimePackageVersion := fmt.Sprintf("%s::%s@%s", selectedRuntime, runtimeSpecificName, v)
237240

cmd/add_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,11 @@ func TestAddCmd_ServerWithArguments(t *testing.T) {
269269
},
270270
},
271271
Arguments: packages.Arguments{
272-
"--endpoint": {VariableType: packages.VariableTypeArg, Required: true},
273-
"--api-key": {VariableType: packages.VariableTypeArg, Required: true},
274-
"--format": {VariableType: packages.VariableTypeArg, Required: false},
272+
"--endpoint": {VariableType: packages.VariableTypeArg, Required: true},
273+
"--api-key": {VariableType: packages.VariableTypeArg, Required: true},
274+
"--format": {VariableType: packages.VariableTypeArg, Required: false},
275275
"--enable-cache": {VariableType: packages.VariableTypeArgBool, Required: true},
276-
"--debug": {VariableType: packages.VariableTypeArgBool, Required: false},
276+
"--debug": {VariableType: packages.VariableTypeArgBool, Required: false},
277277
},
278278
},
279279
expectedRequiredValues: []string{"--endpoint", "--api-key"},
@@ -296,8 +296,8 @@ func TestAddCmd_ServerWithArguments(t *testing.T) {
296296
},
297297
},
298298
Arguments: packages.Arguments{
299-
"OPTIONAL_ENV": {VariableType: packages.VariableTypeEnv, Required: false},
300-
"--optional-flag": {VariableType: packages.VariableTypeArgBool, Required: false},
299+
"OPTIONAL_ENV": {VariableType: packages.VariableTypeEnv, Required: false},
300+
"--optional-flag": {VariableType: packages.VariableTypeArgBool, Required: false},
301301
"--optional-value": {VariableType: packages.VariableTypeArg, Required: false},
302302
},
303303
},

cmd/config/export/export_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ func TestExportCommand_Integration(t *testing.T) {
132132
require.NoError(t, err)
133133
expectedContextContent, err := os.ReadFile(paths.contextFile)
134134
require.NoError(t, err)
135-
require.Equal(t, strings.TrimSpace(string(expectedContextContent)), strings.TrimSpace(string(contextContent)))
135+
require.Equal(
136+
t,
137+
strings.TrimSpace(string(expectedContextContent)),
138+
strings.TrimSpace(string(contextContent)),
139+
)
136140

137141
// Verify contract output content
138142
contractContent, err := os.ReadFile(contractOutput)

cmd/remove_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import (
55
"os"
66
"testing"
77

8-
"github.com/mozilla-ai/mcpd/v2/internal/cmd"
9-
108
"github.com/BurntSushi/toml"
119
"github.com/stretchr/testify/assert"
1210
"github.com/stretchr/testify/require"
1311

12+
"github.com/mozilla-ai/mcpd/v2/internal/cmd"
1413
"github.com/mozilla-ai/mcpd/v2/internal/config"
1514
"github.com/mozilla-ai/mcpd/v2/internal/flags"
1615
)

cmd/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (c *SearchCmd) filters() map[string]string {
142142
f["license"] = c.License
143143
}
144144
if c.IsOfficial {
145-
f["is_official"] = "true"
145+
f["isOfficial"] = "true"
146146
}
147147

148148
return f

cmd/search_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ func TestSearchCmd_Filters(t *testing.T) {
7373
c.License = "MIT"
7474
},
7575
wantFilter: map[string]string{
76-
"is_official": "true",
77-
"license": "MIT",
76+
"isOfficial": "true",
77+
"license": "MIT",
7878
},
7979
},
8080
{
@@ -549,7 +549,11 @@ func (f *fakeRegistryMultiple) Resolve(_ string, _ ...options.ResolveOption) (pa
549549
return packages.Package{}, f.err
550550
}
551551

552-
func (f *fakeRegistryMultiple) Search(_ string, _ map[string]string, _ ...options.SearchOption) ([]packages.Package, error) {
552+
func (f *fakeRegistryMultiple) Search(
553+
_ string,
554+
_ map[string]string,
555+
_ ...options.SearchOption,
556+
) ([]packages.Package, error) {
553557
return f.packages, f.err
554558
}
555559

internal/api/health.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ type ServerHealth struct {
3232
Name string `json:"name"`
3333
Status HealthStatus `json:"status"`
3434
Latency *string `json:"latency,omitempty"`
35-
LastChecked *time.Time `json:"last_checked,omitempty"`
36-
LastSuccessful *time.Time `json:"last_successful,omitempty"`
35+
LastChecked *time.Time `json:"lastChecked,omitempty"`
36+
LastSuccessful *time.Time `json:"lastSuccessful,omitempty"`
3737
}
3838

3939
// ServersHealth represents a collection of ServerHealth.
@@ -44,13 +44,13 @@ type ServersHealth struct {
4444
// ServersHealthResponse is the response for GET /health
4545
type ServersHealthResponse struct {
4646
Body struct {
47-
Servers []ServerHealth `json:"servers" doc:"Tracked MCP server health statuses"`
47+
Servers []ServerHealth `doc:"Tracked MCP server health statuses" json:"servers"`
4848
}
4949
}
5050

5151
// ServerHealthRequest represents the incoming request for obtaining ServerHealth.
5252
type ServerHealthRequest struct {
53-
Name string `path:"name" example:"time" doc:"Name of the server to check"`
53+
Name string `doc:"Name of the server to check" example:"time" path:"name"`
5454
}
5555

5656
// ServerHealthResponse represents the wrapped API response for a ServerHealth.

0 commit comments

Comments
 (0)