Skip to content

Commit eebaa0e

Browse files
fix: resolve all 89 golangci-lint errors (#2)
* fix: resolve all 89 golangci-lint errors - Remove unused code (types, functions, constants, imports) - 22 fixes - Replace WriteString(fmt.Sprintf(...)) with fmt.Fprintf(...) - 14 staticcheck fixes - Remove dead variable assignments - 3 ineffassign fixes - Add _ = for unchecked AddTags/DeleteAllTags/Shutdown/Close calls - 50 errcheck fixes * refactor: assert errors from HandleRequest in test setup calls Replace _, _ = p.HandleRequest(...) with proper error capture and require.NoError(t, err) assertions in s3 and iam provider tests. * fix: sanitize uploadID in multipartDir to prevent path traversal Use filepath.Base to strip any path separators from uploadID before constructing the multipart directory path. * Potential fix for pull request finding 'CodeQL / Uncontrolled data used in path expression' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Potential fix for pull request finding 'CodeQL / Uncontrolled data used in path expression' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 2780ce6 commit eebaa0e

295 files changed

Lines changed: 1505 additions & 1596 deletions

File tree

Some content is hidden

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

cmd/devcloud/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func main() {
105105
// 404 handler so the dashboard routes don't leak service internals.
106106
bus := eventbus.New()
107107
logCollector := dashboard.NewLogCollector(1000)
108-
var dashHandler http.Handler = http.NotFoundHandler()
108+
dashHandler := http.NotFoundHandler()
109109
webDir := ""
110110
if cfg.Dashboard.Enabled {
111111
dashAPI := dashboard.NewDashboardAPI(registry, logCollector)

internal/codegen/parser.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func ParseSmithyJSON(data []byte) (*SmithyModel, error) {
105105
}
106106
if httpTrait, ok := opShape.Traits["smithy.api#http"]; ok {
107107
var ht rawHTTPTrait
108-
json.Unmarshal(httpTrait, &ht) //nolint:errcheck
108+
_ = json.Unmarshal(httpTrait, &ht) //nolint:errcheck
109109
op.HTTPMethod = ht.Method
110110
op.HTTPUri = ht.URI
111111
}
@@ -146,12 +146,12 @@ func ParseSmithyJSON(data []byte) (*SmithyModel, error) {
146146
}
147147
if hdr, ok := member.Traits["smithy.api#httpHeader"]; ok {
148148
var headerName string
149-
json.Unmarshal(hdr, &headerName) //nolint:errcheck
149+
_ = json.Unmarshal(hdr, &headerName) //nolint:errcheck
150150
m.HTTPHeader = headerName
151151
}
152152
if q, ok := member.Traits["smithy.api#httpQuery"]; ok {
153153
var queryName string
154-
json.Unmarshal(q, &queryName) //nolint:errcheck
154+
_ = json.Unmarshal(q, &queryName) //nolint:errcheck
155155
m.HTTPQuery = queryName
156156
}
157157
}
@@ -163,11 +163,11 @@ func ParseSmithyJSON(data []byte) (*SmithyModel, error) {
163163

164164
if errType, ok := rs.Traits["smithy.api#error"]; ok {
165165
var et string
166-
json.Unmarshal(errType, &et) //nolint:errcheck
166+
_ = json.Unmarshal(errType, &et) //nolint:errcheck
167167
shape.ErrorTrait = &ErrorTrait{Type: et}
168168
if httpErr, ok := rs.Traits["smithy.api#httpError"]; ok {
169169
var status int
170-
json.Unmarshal(httpErr, &status) //nolint:errcheck
170+
_ = json.Unmarshal(httpErr, &status) //nolint:errcheck
171171
shape.ErrorTrait.HTTPStatus = status
172172
}
173173
}

internal/dashboard/api_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ func newTestRegistry(p *mockServicePlugin) *plugin.Registry {
4848
reg.Register(p.id, func(cfg plugin.PluginConfig) plugin.ServicePlugin {
4949
return captured
5050
})
51-
reg.Init(p.id, plugin.PluginConfig{}) //nolint:errcheck
51+
_, err := reg.Init(p.id, plugin.PluginConfig{})
52+
_ = err
5253
return reg
5354
}
5455

internal/dashboard/websocket.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (h *Hub) ServeWS(w http.ResponseWriter, r *http.Request) {
9393
h.mu.Lock()
9494
delete(h.clients, client)
9595
h.mu.Unlock()
96-
conn.Close()
96+
_ = conn.Close()
9797
})
9898
}
9999

internal/dashboard/websocket_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestHub_ClientConnects(t *testing.T) {
4242
defer server.Close()
4343

4444
conn := dialWS(t, wsURL(server.URL))
45-
defer conn.Close()
45+
defer func() { _ = conn.Close() }()
4646

4747
// Give the hub a moment to register the client.
4848
time.Sleep(50 * time.Millisecond)
@@ -65,7 +65,7 @@ func TestHub_BroadcastEvent(t *testing.T) {
6565
defer server.Close()
6666

6767
conn := dialWS(t, wsURL(server.URL))
68-
defer conn.Close()
68+
defer func() { _ = conn.Close() }()
6969

7070
// Allow the hub to register the client before publishing.
7171
time.Sleep(50 * time.Millisecond)
@@ -81,7 +81,7 @@ func TestHub_BroadcastEvent(t *testing.T) {
8181
require.NoError(t, err)
8282

8383
// Read message with a deadline to avoid hanging on failure.
84-
conn.SetReadDeadline(time.Now().Add(2 * time.Second))
84+
_ = conn.SetReadDeadline(time.Now().Add(2 * time.Second))
8585
_, raw, err := conn.ReadMessage()
8686
require.NoError(t, err)
8787

internal/eventbus/eventbus_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ func TestPublishAndSubscribe(t *testing.T) {
2424
})
2525
defer unsub()
2626

27-
err := bus.Publish(context.Background(), Event{
27+
require.NoError(t, bus.Publish(context.Background(), Event{
2828
Source: "s3",
2929
Type: "s3:ObjectCreated",
3030
Detail: map[string]any{"bucket": "test", "key": "hello.txt"},
31-
})
32-
require.NoError(t, err)
31+
}))
3332

3433
time.Sleep(50 * time.Millisecond)
3534
mu.Lock()
@@ -51,8 +50,8 @@ func TestSubscribeWildcard(t *testing.T) {
5150
})
5251
defer unsub()
5352

54-
bus.Publish(context.Background(), Event{Source: "s3", Type: "s3:ObjectCreated"})
55-
bus.Publish(context.Background(), Event{Source: "sqs", Type: "sqs:MessageSent"})
53+
require.NoError(t, bus.Publish(context.Background(), Event{Source: "s3", Type: "s3:ObjectCreated"}))
54+
require.NoError(t, bus.Publish(context.Background(), Event{Source: "sqs", Type: "sqs:MessageSent"}))
5655

5756
time.Sleep(50 * time.Millisecond)
5857
mu.Lock()
@@ -71,12 +70,12 @@ func TestUnsubscribe(t *testing.T) {
7170
mu.Unlock()
7271
})
7372

74-
bus.Publish(context.Background(), Event{Type: "test"})
73+
require.NoError(t, bus.Publish(context.Background(), Event{Type: "test"}))
7574
time.Sleep(50 * time.Millisecond)
7675

7776
unsub()
7877

79-
bus.Publish(context.Background(), Event{Type: "test"})
78+
require.NoError(t, bus.Publish(context.Background(), Event{Type: "test"}))
8079
time.Sleep(50 * time.Millisecond)
8180

8281
mu.Lock()

internal/gateway/gateway_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestGateway_Integration(t *testing.T) {
3838

3939
res, err := http.Get(srv.URL + "/")
4040
require.NoError(t, err)
41-
defer res.Body.Close()
41+
defer func() { _ = res.Body.Close() }()
4242

4343
assert.Equal(t, http.StatusOK, res.StatusCode)
4444
// Middleware headers must be present.

internal/gateway/middleware.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ func ErrorRecoveryMiddleware(next http.Handler) http.Handler {
7878
strings.HasPrefix(r.URL.Path, "/2015-03-31/") {
7979
w.Header().Set("Content-Type", "application/json")
8080
w.WriteHeader(http.StatusInternalServerError)
81-
fmt.Fprintf(w, `{"__type":"InternalError","message":"%v"}`, rec)
81+
_, _ = fmt.Fprintf(w, `{"__type":"InternalError","message":"%v"}`, rec)
8282
} else {
8383
w.Header().Set("Content-Type", "application/xml")
8484
w.WriteHeader(http.StatusInternalServerError)
85-
fmt.Fprintf(w, `<?xml version="1.0" encoding="UTF-8"?><Error><Code>InternalError</Code><Message>%v</Message></Error>`, rec)
85+
_, _ = fmt.Fprintf(w, `<?xml version="1.0" encoding="UTF-8"?><Error><Code>InternalError</Code><Message>%v</Message></Error>`, rec)
8686
}
8787
}
8888
}()

internal/plugin/registry_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func TestRegistryGetUnknown(t *testing.T) {
4242
func TestRegistryList(t *testing.T) {
4343
reg := NewRegistry()
4444
reg.Register("s3", func(cfg PluginConfig) ServicePlugin { return &mockPlugin{} })
45-
reg.Init("s3", PluginConfig{})
45+
_, err := reg.Init("s3", PluginConfig{})
46+
require.NoError(t, err)
4647
assert.Equal(t, []string{"s3"}, reg.ActiveServices())
4748
}

internal/services/account/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (p *AccountProvider) HandleRequest(_ context.Context, op string, req *http.
5050
body, _ := io.ReadAll(req.Body)
5151
var bodyMap map[string]any
5252
if len(body) > 0 {
53-
json.Unmarshal(body, &bodyMap)
53+
_ = json.Unmarshal(body, &bodyMap)
5454
}
5555
if bodyMap == nil {
5656
bodyMap = map[string]any{}

0 commit comments

Comments
 (0)