Skip to content

Commit d60f8bf

Browse files
committed
fix: resolve all golangci-lint and gofumpt issues
1 parent 88a2d36 commit d60f8bf

84 files changed

Lines changed: 793 additions & 739 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/lint.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,15 @@ jobs:
4444
echo "Run 'gofumpt -w .' to fix."
4545
exit 1
4646
fi
47+
48+
openapi:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
53+
- uses: actions/setup-node@v4
54+
with:
55+
node-version: 22
56+
57+
- name: Lint OpenAPI spec
58+
run: npx @redocly/cli lint api/openapi.yaml

.golangci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: "2"
2+
3+
linters:
4+
enable:
5+
- errcheck
6+
- govet
7+
- staticcheck
8+
- unused
9+
- ineffassign
10+
- unparam
11+
- revive
12+
- errorlint
13+
- recvcheck
14+
- bodyclose
15+
16+
formatters:
17+
enable:
18+
- gci

cmd/sluice/audit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestHandleAuditVerifyBroken(t *testing.T) {
8787
t.Fatal(err)
8888
}
8989
tampered := strings.Replace(string(data), `"prev_hash":"`, `"prev_hash":"00`, 1)
90-
if err := os.WriteFile(logPath, []byte(tampered), 0600); err != nil {
90+
if err := os.WriteFile(logPath, []byte(tampered), 0o600); err != nil {
9191
t.Fatal(err)
9292
}
9393

cmd/sluice/cert_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func TestCertGeneratePermissions(t *testing.T) {
108108
t.Fatalf("stat ca-key.pem: %v", err)
109109
}
110110
perm := info.Mode().Perm()
111-
if perm != 0600 {
111+
if perm != 0o600 {
112112
t.Errorf("ca-key.pem permissions: %o, want 0600", perm)
113113
}
114114

@@ -119,7 +119,7 @@ func TestCertGeneratePermissions(t *testing.T) {
119119
t.Fatalf("stat ca-cert.pem: %v", err)
120120
}
121121
perm = info.Mode().Perm()
122-
if perm != 0644 {
122+
if perm != 0o644 {
123123
t.Errorf("ca-cert.pem permissions: %o, want 0644", perm)
124124
}
125125
}

cmd/sluice/channel.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func handleChannelCommand(args []string) error {
1313
if len(args) == 0 {
14-
return fmt.Errorf("usage: sluice channel [list|add|update|remove] ...")
14+
return fmt.Errorf("usage: sluice channel [list|add|update|remove]")
1515
}
1616

1717
switch args[0] {
@@ -24,7 +24,7 @@ func handleChannelCommand(args []string) error {
2424
case "remove":
2525
return handleChannelRemove(args[1:])
2626
default:
27-
return fmt.Errorf("unknown channel command: %s\nusage: sluice channel [list|add|update|remove] ...", args[0])
27+
return fmt.Errorf("unknown channel command: %s, usage: sluice channel [list|add|update|remove]", args[0])
2828
}
2929
}
3030

cmd/sluice/cred.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const credAddSourcePrefix = "cred-add:"
2525

2626
func handleCredCommand(args []string) error {
2727
if len(args) == 0 {
28-
return fmt.Errorf("usage: sluice cred [add|list|remove] ...")
28+
return fmt.Errorf("usage: sluice cred [add|list|remove]")
2929
}
3030

3131
switch args[0] {
@@ -36,7 +36,7 @@ func handleCredCommand(args []string) error {
3636
case "remove":
3737
return handleCredRemove(args[1:])
3838
default:
39-
return fmt.Errorf("unknown cred command: %s\nusage: sluice cred [add|list|remove] ...", args[0])
39+
return fmt.Errorf("unknown cred command: %s (usage: sluice cred [add|list|remove] ...)", args[0])
4040
}
4141
}
4242

@@ -85,9 +85,9 @@ func openVaultStore(dbPath string) (*vault.Store, error) {
8585
}
8686
}
8787
if !hasAge {
88-
return nil, fmt.Errorf("vault_providers is configured as %v without the age backend. "+
89-
"CLI credential management only supports the age backend. "+
90-
"Manage credentials through the configured providers' native tools.", cfg.VaultProviders)
88+
return nil, fmt.Errorf("vault_providers is configured as %v without the age backend, "+
89+
"CLI credential management only supports the age backend, "+
90+
"manage credentials through the configured providers' native tools", cfg.VaultProviders)
9191
}
9292
if !ageFirst {
9393
log.Printf("warning: vault_providers is %v. The age backend is not the "+
@@ -96,8 +96,8 @@ func openVaultStore(dbPath string) (*vault.Store, error) {
9696
}
9797
} else if cfg.VaultProvider != "" && cfg.VaultProvider != "age" {
9898
// Single provider that is not age.
99-
return nil, fmt.Errorf("vault provider is %q; CLI credential management only supports the age backend. "+
100-
"Manage credentials through the %s provider's native tools.", cfg.VaultProvider, cfg.VaultProvider)
99+
return nil, fmt.Errorf("vault provider is %q, CLI credential management only supports the age backend, "+
100+
"manage credentials through the %s provider's native tools", cfg.VaultProvider, cfg.VaultProvider)
101101
}
102102
}
103103
}

cmd/sluice/main.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package main implements the sluice CLI.
12
package main
23

34
import (
@@ -669,12 +670,12 @@ func readBindings(db *store.Store) ([]vault.Binding, error) {
669670
bindings := make([]vault.Binding, len(rows))
670671
for i, r := range rows {
671672
bindings[i] = vault.Binding{
672-
Destination: r.Destination,
673-
Ports: r.Ports,
674-
Credential: r.Credential,
675-
Header: r.Header,
676-
Template: r.Template,
677-
Protocols: r.Protocols,
673+
Destination: r.Destination,
674+
Ports: r.Ports,
675+
Credential: r.Credential,
676+
Header: r.Header,
677+
Template: r.Template,
678+
Protocols: r.Protocols,
678679
}
679680
}
680681
return bindings, nil

cmd/sluice/main_test.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func TestDrainSignals(t *testing.T) {
158158
}
159159

160160
// TestDrainSignalsEmpty verifies drainSignals is a no-op on empty channel.
161-
func TestDrainSignalsEmpty(t *testing.T) {
161+
func TestDrainSignalsEmpty(_ *testing.T) {
162162
ch := make(chan os.Signal, 5)
163163
drainSignals(ch) // should not block
164164
}
@@ -357,7 +357,7 @@ credential = "example_key"
357357
header = "Authorization"
358358
template = "Bearer {value}"
359359
`
360-
if err := os.WriteFile(tomlPath, []byte(tomlData), 0644); err != nil {
360+
if err := os.WriteFile(tomlPath, []byte(tomlData), 0o644); err != nil {
361361
t.Fatal(err)
362362
}
363363

@@ -522,8 +522,8 @@ func TestReadVaultConfig(t *testing.T) {
522522
vaddr := "https://vault.example.com:8200"
523523
vmount := "secret"
524524
_ = db.UpdateConfig(store.ConfigUpdate{
525-
VaultProvider: &vprov,
526-
VaultHashicorpAddr: &vaddr,
525+
VaultProvider: &vprov,
526+
VaultHashicorpAddr: &vaddr,
527527
VaultHashicorpMount: &vmount,
528528
})
529529

@@ -733,7 +733,7 @@ func TestIsDockerSocketAvailable(t *testing.T) {
733733
if err != nil {
734734
t.Fatal(err)
735735
}
736-
defer l.Close()
736+
defer func() { _ = l.Close() }()
737737

738738
if !isDockerSocketAvailable(sockPath) {
739739
t.Error("expected true for real Unix socket")
@@ -746,7 +746,7 @@ func TestIsDockerSocketAvailable(t *testing.T) {
746746

747747
// Regular file is not a socket.
748748
regularPath := filepath.Join(dir, "file.txt")
749-
if err := os.WriteFile(regularPath, []byte("hello"), 0644); err != nil {
749+
if err := os.WriteFile(regularPath, []byte("hello"), 0o644); err != nil {
750750
t.Fatal(err)
751751
}
752752
if isDockerSocketAvailable(regularPath) {
@@ -765,7 +765,7 @@ func TestIsAppleCLIAvailable(t *testing.T) {
765765
}
766766

767767
// TestIsTartCLIAvailable verifies the function returns without panicking.
768-
func TestIsTartCLIAvailable(t *testing.T) {
768+
func TestIsTartCLIAvailable(_ *testing.T) {
769769
// Just verify the function doesn't panic. tart may or may not be installed.
770770
_ = isTartCLIAvailable()
771771
}
@@ -835,13 +835,12 @@ func TestStandaloneModeStartup(t *testing.T) {
835835
}
836836
}
837837

838-
839838
// TestBuildSelfBypass verifies the self-bypass address expansion.
840839
func TestBuildSelfBypass(t *testing.T) {
841840
tests := []struct {
842-
name string
843-
addr string
844-
want []string
841+
name string
842+
addr string
843+
want []string
845844
}{
846845
{
847846
name: "specific IP",
@@ -1007,7 +1006,7 @@ ports = [443]
10071006
credential = "seeded_key"
10081007
header = "Authorization"
10091008
`
1010-
if err := os.WriteFile(tomlPath, []byte(tomlData), 0644); err != nil {
1009+
if err := os.WriteFile(tomlPath, []byte(tomlData), 0o644); err != nil {
10111010
t.Fatal(err)
10121011
}
10131012

@@ -1141,7 +1140,7 @@ default = "deny"
11411140
destination = "seeded.example.com"
11421141
ports = [443]
11431142
`
1144-
if err := os.WriteFile(tomlPath, []byte(tomlData), 0644); err != nil {
1143+
if err := os.WriteFile(tomlPath, []byte(tomlData), 0o644); err != nil {
11451144
t.Fatal(err)
11461145
}
11471146

@@ -1190,7 +1189,7 @@ func TestSeedStoreFromConfigMissing(t *testing.T) {
11901189
func TestSeedStoreFromConfigMalformed(t *testing.T) {
11911190
dir := t.TempDir()
11921191
tomlPath := filepath.Join(dir, "bad.toml")
1193-
if err := os.WriteFile(tomlPath, []byte("not valid toml [[["), 0644); err != nil {
1192+
if err := os.WriteFile(tomlPath, []byte("not valid toml [[["), 0o644); err != nil {
11941193
t.Fatal(err)
11951194
}
11961195

@@ -1355,7 +1354,7 @@ func TestMacOSRuntimeSelectionRequiresExplicit(t *testing.T) {
13551354
// shutdownMacOSVM accepts the expected parameter types (including nil router
13561355
// and ownership boolean).
13571356
var (
1358-
_ container.ContainerManager = (*container.TartManager)(nil)
1357+
_ container.ContainerManager = (*container.TartManager)(nil)
13591358
_ func(*container.TartManager, *container.NetworkRouter, bool) = shutdownMacOSVM
13601359
)
13611360

cmd/sluice/mcp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ func writeMCPServersJSON(phantomDir, sluiceURL string) {
427427
return
428428
}
429429
path := filepath.Join(phantomDir, "mcp-servers.json")
430-
if err := os.WriteFile(path, data, 0600); err != nil {
430+
if err := os.WriteFile(path, data, 0o600); err != nil {
431431
log.Printf("WARNING: failed to write %s: %v", path, err)
432432
}
433433
}

cmd/sluice/mcp_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67
"os"
78
"os/exec"
@@ -557,7 +558,8 @@ func TestHandleMCPGatewayInvalidChatID(t *testing.T) {
557558
"TEST_DB_PATH="+dbPath,
558559
)
559560
err = cmd.Run()
560-
if e, ok := err.(*exec.ExitError); ok && !e.Success() {
561+
var e *exec.ExitError
562+
if errors.As(err, &e) && !e.Success() {
561563
return
562564
}
563565
t.Fatal("expected non-zero exit code for invalid chat ID")
@@ -751,7 +753,7 @@ func TestWriteMCPServersJSONCustomURL(t *testing.T) {
751753
}
752754

753755
// TestWriteMCPServersJSONInvalidDir verifies graceful handling of invalid dir.
754-
func TestWriteMCPServersJSONInvalidDir(t *testing.T) {
756+
func TestWriteMCPServersJSONInvalidDir(_ *testing.T) {
755757
// Should not panic on unwritable path.
756758
writeMCPServersJSON("/nonexistent/path/foo", "http://127.0.0.1:3000/mcp")
757759
}
@@ -805,7 +807,7 @@ default = "deny"
805807
destination = "api.example.com"
806808
ports = [443]
807809
name = "test rule"
808-
`), 0600); err != nil {
810+
`), 0o600); err != nil {
809811
t.Fatal(err)
810812
}
811813

0 commit comments

Comments
 (0)