Skip to content

Commit f5294a3

Browse files
author
Zied Elouaer
committed
chore: fix golang linter config and issues
1 parent ceabcf4 commit f5294a3

10 files changed

Lines changed: 113 additions & 115 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ jobs:
113113
uses: actions/upload-artifact@v4
114114
with:
115115
name: terramate-mcp-server-${{ matrix.os }}
116-
path: bin/terramate-mcp-server${{ matrix.os == 'windows-latest' && '.exe' || '' }}
116+
path: bin/terramate-mcp-server
117117
retention-days: 7
118118

119119
docker:

.golangci.yml

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,65 @@
1+
version: "2"
2+
13
run:
24
timeout: 5m
35
tests: true
46
allow-parallel-runners: true
57

6-
output:
7-
sort-results: true
8-
9-
linters-settings:
10-
govet:
11-
enable:
12-
- shadow
13-
gofumpt:
14-
extra-rules: false
15-
gocyclo:
16-
min-complexity: 15
17-
goconst:
18-
min-len: 3
19-
min-occurrences: 3
20-
gocritic:
21-
enabled-checks:
22-
- sloppyReassign
23-
- boolExprSimplify
24-
revive:
25-
rules:
26-
- name: var-naming
27-
- name: exported
28-
arguments: ["checkPrivateReceivers"]
29-
- name: errorf
30-
- name: blank-imports
31-
- name: context-as-argument
32-
- name: error-return
33-
- name: increment-decrement
34-
- name: unexported-return
35-
misspell:
36-
locale: US
37-
dupl:
38-
threshold: 150
39-
408
linters:
41-
disable-all: true
9+
default: none
4210
enable:
4311
- govet
44-
- gofumpt
4512
- revive
4613
- errcheck
4714
- staticcheck
48-
- gosimple
4915
- ineffassign
50-
- typecheck
5116
- unused
5217
- gocyclo
5318
- goconst
5419
- nakedret
5520
- unparam
5621
- misspell
57-
- gocritic
22+
settings:
23+
govet:
24+
enable:
25+
- shadow
26+
gocyclo:
27+
min-complexity: 15
28+
goconst:
29+
min-len: 3
30+
min-occurrences: 3
31+
revive:
32+
rules:
33+
- name: var-naming
34+
- name: exported
35+
arguments: ["checkPrivateReceivers"]
36+
- name: errorf
37+
- name: blank-imports
38+
- name: context-as-argument
39+
- name: error-return
40+
- name: increment-decrement
41+
- name: unexported-return
42+
misspell:
43+
locale: US
44+
exclusions:
45+
rules:
46+
- linters: [revive]
47+
text: "exported: exported function .* should have comment or be unexported"
48+
- linters: [revive]
49+
text: "package-comments: should have a package comment"
50+
- linters: [revive]
51+
path: "types/"
52+
text: "var-naming: avoid meaningless package names"
53+
- linters: [goconst, gocyclo]
54+
path: "_test\\.go"
55+
56+
formatters:
57+
enable:
58+
- gofumpt
59+
settings:
60+
gofumpt:
61+
extra-rules: false
5862

5963
issues:
60-
exclude-use-default: false
6164
max-issues-per-linter: 0
6265
max-same-issues: 0
63-
exclude-rules:
64-
- linters: [revive]
65-
text: "exported: exported function .* should have comment or be unexported"
66-
- linters: [revive]
67-
text: "package-comments: should have a package comment"
68-
- linters: [goconst]
69-
path: "_test\\.go"
70-
71-

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ GOMOD := $(GOCMD) mod
3939
GOFMT := gofmt
4040
TOOLS_BIN := $(BUILD_DIR)/tools
4141
GOLANGCI_LINT := $(TOOLS_BIN)/golangci-lint
42-
GOLANGCI_LINT_VERSION ?= v1.62.0
42+
GOLANGCI_LINT_VERSION ?= v2.5.0
4343
GOTOOLCHAIN ?= go1.25.3
4444
GOLANGCI_LINT_TOOLCHAIN ?= go1.25.3
4545

@@ -103,7 +103,7 @@ test/short: ## Run tests (skip slow tests)
103103
$(GOLANGCI_LINT): ## Install golangci-lint locally via go install
104104
@echo "Installing golangci-lint..."
105105
@mkdir -p $(TOOLS_BIN)
106-
@GOTOOLCHAIN=$(GOLANGCI_LINT_TOOLCHAIN) GOBIN=$(abspath $(TOOLS_BIN)) $(GOCMD) install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
106+
@GOTOOLCHAIN=$(GOLANGCI_LINT_TOOLCHAIN) GOBIN=$(abspath $(TOOLS_BIN)) $(GOCMD) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
107107
@echo "✅ golangci-lint installed at $(GOLANGCI_LINT)"
108108

109109
## Lint and format targets

sdk/terramate/README.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"context"
3434
"fmt"
3535
"log"
36-
36+
3737
"github.com/terramate-io/terramate-mcp-server/sdk/terramate"
3838
)
3939

@@ -45,32 +45,32 @@ func main() {
4545
if err != nil {
4646
log.Fatalf("Failed to load credentials: %v\nRun 'terramate cloud login' first", err)
4747
}
48-
48+
4949
// Create client with JWT
5050
client, err := terramate.NewClient(credential,
5151
terramate.WithRegion("eu"))
5252
if err != nil {
5353
log.Fatal(err)
5454
}
55-
55+
5656
ctx := context.Background()
57-
57+
5858
// List organizations
5959
memberships, _, err := client.Memberships.List(ctx)
6060
if err != nil {
6161
log.Fatal(err)
6262
}
63-
63+
6464
orgUUID := memberships[0].OrgUUID
65-
65+
6666
// List drifted stacks
6767
stacks, _, err := client.Stacks.List(ctx, orgUUID, &terramate.StacksListOptions{
6868
DriftStatus: []string{"drifted"},
6969
})
7070
if err != nil {
7171
log.Fatal(err)
7272
}
73-
73+
7474
fmt.Printf("Found %d drifted stacks\n", len(stacks.Stacks))
7575
}
7676
```
@@ -308,11 +308,11 @@ details, _, err := client.ReviewRequests.Get(ctx, orgUUID, reviewRequestID, nil)
308308
for _, sp := range details.StackPreviews {
309309
fmt.Printf("Stack: %s\n", sp.Stack.Path)
310310
fmt.Printf("Status: %s\n", sp.Status)
311-
311+
312312
if sp.ChangesetDetails != nil {
313313
fmt.Println(sp.ChangesetDetails.ChangesetASCII) // Terraform plan
314314
}
315-
315+
316316
// See change counts
317317
if sp.ResourceChanges != nil {
318318
fmt.Printf("Creates: %d, Updates: %d, Deletes: %d\n",
@@ -345,7 +345,7 @@ deployments, _, err := client.Deployments.List(ctx, orgUUID,
345345

346346
for _, d := range deployments.Deployments {
347347
fmt.Printf("Deployment #%d: %s\n", d.ID, d.CommitTitle)
348-
fmt.Printf("Status: %s (%d ok, %d failed)\n",
348+
fmt.Printf("Status: %s (%d ok, %d failed)\n",
349349
d.Status, d.OkCount, d.FailedCount)
350350
}
351351

@@ -478,15 +478,15 @@ stacks, _, _ := client.Stacks.List(ctx, orgUUID, &terramate.StacksListOptions{
478478

479479
// 2. For each drifted stack, get the drift details
480480
for _, stack := range stacks.Stacks {
481-
drifts, _, _ := client.Drifts.ListForStack(ctx, orgUUID, stack.StackID,
481+
drifts, _, _ := client.Drifts.ListForStack(ctx, orgUUID, stack.StackID,
482482
&terramate.DriftsListOptions{
483483
DriftStatus: []string{"drifted"},
484484
PerPage: 1, // Just the latest
485485
})
486-
486+
487487
if len(drifts.Drifts) > 0 {
488488
drift, _, _ := client.Drifts.Get(ctx, orgUUID, stack.StackID, drifts.Drifts[0].ID)
489-
489+
490490
fmt.Printf("Stack: %s\n", stack.MetaName)
491491
fmt.Printf("Drift Plan:\n%s\n", drift.DriftDetails.ChangesetASCII)
492492
}
@@ -503,7 +503,7 @@ reviews, _, _ := client.ReviewRequests.List(ctx, orgUUID,
503503
})
504504

505505
// 2. Get PR with all stack terraform plans
506-
details, _, _ := client.ReviewRequests.Get(ctx, orgUUID,
506+
details, _, _ := client.ReviewRequests.Get(ctx, orgUUID,
507507
reviews.ReviewRequests[0].ReviewRequestID, nil)
508508

509509
// 3. Analyze each stack's changes
@@ -533,10 +533,10 @@ deployments, _, _ := client.Deployments.List(ctx, orgUUID,
533533
for _, d := range deployments.Deployments {
534534
fmt.Printf("\nDeployment #%d: %s\n", d.ID, d.CommitTitle)
535535
fmt.Printf("Failed stacks: %d/%d\n", d.FailedCount, d.StackDeploymentTotalCount)
536-
536+
537537
// 3. Get individual stack failures
538538
stackDeployments, _, _ := client.Deployments.ListForWorkflow(ctx, orgUUID, d.ID, nil)
539-
539+
540540
for _, sd := range stackDeployments.StackDeployments {
541541
if sd.Status == "failed" {
542542
deployment, _, _ := client.Deployments.GetStackDeployment(ctx, orgUUID, sd.ID)
@@ -565,20 +565,20 @@ details, _, _ := client.ReviewRequests.Get(ctx, orgUUID, reviews.ReviewRequests[
565565
for _, sp := range details.StackPreviews {
566566
if sp.Status == "failed" {
567567
fmt.Printf("\n❌ Failed: %s (Preview ID: %d)\n", sp.Stack.Path, sp.StackPreviewID)
568-
568+
569569
// 4. Get error logs for AI analysis
570570
logs, _, _ := client.Previews.GetLogs(ctx, orgUUID, sp.StackPreviewID,
571571
&terramate.PreviewLogsOptions{
572572
Channel: "stderr", // Error messages
573573
PerPage: 100,
574574
})
575-
575+
576576
// 5. Display logs for AI to analyze
577577
fmt.Println("Error logs:")
578578
for _, log := range logs.StackPreviewLogLines {
579579
fmt.Printf("[%s] %s\n", log.Timestamp.Format("15:04:05"), log.Message)
580580
}
581-
581+
582582
// AI can now analyze these logs and suggest fixes
583583
// Example errors:
584584
// - Provider authentication issues
@@ -611,19 +611,19 @@ stackDeps, _, _ := client.Deployments.ListForWorkflow(ctx, orgUUID, workflow.ID,
611611
for _, sd := range stackDeps.StackDeployments {
612612
if sd.Status == "failed" {
613613
// 4. Get deployment logs for AI analysis
614-
logs, _, _ := client.Deployments.GetDeploymentLogs(ctx, orgUUID,
614+
logs, _, _ := client.Deployments.GetDeploymentLogs(ctx, orgUUID,
615615
sd.Stack.StackID, sd.DeploymentUUID,
616616
&terramate.DeploymentLogsOptions{
617617
Channel: "stderr",
618618
PerPage: 100,
619619
})
620-
620+
621621
fmt.Printf("\n❌ Failed deployment: %s\n", sd.Path)
622622
fmt.Println("Error logs:")
623623
for _, log := range logs.DeploymentLogLines {
624624
fmt.Printf("[%s] %s\n", log.Timestamp.Format("15:04:05"), log.Message)
625625
}
626-
626+
627627
// AI analyzes logs and provides:
628628
// - Root cause identification
629629
// - Fix suggestions

sdk/terramate/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (c *Client) newRequest(ctx context.Context, method, path string, body io.Re
187187
// Go's http package only sets GetBody automatically for certain types like
188188
// *bytes.Buffer, *bytes.Reader, *strings.Reader. For custom io.Reader types,
189189
// we need to read the body into a buffer to enable cloning.
190-
var bodyReader io.Reader = body
190+
bodyReader := body
191191
if body != nil {
192192
// Check if body is a type that Go's http package recognizes and sets GetBody for.
193193
// Known types: *bytes.Buffer, *bytes.Reader, *strings.Reader

sdk/terramate/credential.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,12 @@ func parseJWTToken(token string) (provider string, err error) {
695695
// extractProviderFromIssuer extracts a friendly provider name from JWT issuer
696696
func extractProviderFromIssuer(issuer string) string {
697697
// Common issuer patterns
698-
switch {
699-
case issuer == "https://accounts.google.com" || issuer == "accounts.google.com":
698+
switch issuer {
699+
case "https://accounts.google.com", "accounts.google.com":
700700
return providerGoogle
701-
case issuer == "https://token.actions.githubusercontent.com" || issuer == "token.actions.githubusercontent.com":
701+
case "https://token.actions.githubusercontent.com", "token.actions.githubusercontent.com":
702702
return providerGitHubActions
703-
case issuer == "https://gitlab.com":
703+
case "https://gitlab.com":
704704
return providerGitLab
705705
default:
706706
return issuer

sdk/terramate/credential_refresh_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,10 @@ func TestJWTCredential_reloadFromFile(t *testing.T) {
790790

791791
// testReloadUpdatesCredential tests that reloading updates the credential fields.
792792
func testReloadUpdatesCredential(t *testing.T) {
793+
// Skip on Windows: file write/reload timing can differ (e.g. delayed visibility).
794+
if runtime.GOOS == "windows" {
795+
t.Skip("reload from file behavior differs on Windows")
796+
}
793797
tmpDir := t.TempDir()
794798
credFile := filepath.Join(tmpDir, "credentials.tmrc.json")
795799

sdk/terramate/resources_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,17 @@ func TestResourcesList_QueryParams(t *testing.T) {
111111
}
112112
w.Header().Set("Content-Type", "application/json")
113113
w.WriteHeader(200)
114-
w.Write([]byte(`{"resources":[],"paginated_result":{"total":0,"page":2,"per_page":50}}`))
114+
_, _ = w.Write([]byte(`{"resources":[],"paginated_result":{"total":0,"page":2,"per_page":50}}`))
115115
})
116116
defer cleanup()
117117

118118
opts := &ResourcesListOptions{
119-
ListOptions: ListOptions{Page: 2, PerPage: 50},
120-
StackID: 42,
121-
Status: []string{"ok", "drifted"},
122-
Technology: []string{"terraform"},
123-
Type: []string{"aws_vpc"},
124-
Search: "vpc",
119+
ListOptions: ListOptions{Page: 2, PerPage: 50},
120+
StackID: 42,
121+
Status: []string{"ok", "drifted"},
122+
Technology: []string{"terraform"},
123+
Type: []string{"aws_vpc"},
124+
Search: "vpc",
125125
}
126126
_, _, err := client.Resources.List(context.Background(), "org-uuid", opts)
127127
if err != nil {
@@ -178,7 +178,7 @@ func TestResourcesGet_ParsesResponse(t *testing.T) {
178178
}
179179
w.Header().Set("Content-Type", "application/json")
180180
w.WriteHeader(200)
181-
w.Write([]byte(payload))
181+
_, _ = w.Write([]byte(payload))
182182
})
183183
defer cleanup()
184184

0 commit comments

Comments
 (0)