Skip to content

Commit 2705046

Browse files
authored
Enable usestdlibvars linter and fix all violations (#4978)
## Summary - Enable the `usestdlibvars` golangci-lint linter, which detects places where Go standard library constants should be used instead of literal values - Auto-fixed all violations: HTTP method strings (`"GET"`, `"POST"`, etc.) replaced with `http.Method*` constants, and HTTP status codes (`404`, `409`) replaced with `http.Status*` constants ## Test plan - [x] `make checks fmt lint` passes - [x] All unit tests pass (5025 tests) - [x] No new acceptance test failures
1 parent a33efee commit 2705046

11 files changed

Lines changed: 35 additions & 32 deletions

File tree

.golangci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ linters:
2020
- copyloopvar
2121
- forbidigo
2222
- depguard
23+
- usestdlibvars
2324
settings:
2425
depguard:
2526
rules:

bundle/direct/dresources/postgres_endpoint.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dresources
33
import (
44
"context"
55
"errors"
6+
"net/http"
67
"strings"
78
"time"
89

@@ -180,7 +181,7 @@ func (r *ResourcePostgresEndpoint) DoDelete(ctx context.Context, id string) erro
180181
if err != nil {
181182
// Check if this is a reconciliation in progress error
182183
var apiErr *apierr.APIError
183-
if errors.As(err, &apiErr) && apiErr.StatusCode == 409 &&
184+
if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusConflict &&
184185
strings.Contains(apiErr.Message, "reconciliation") {
185186
// Check if we've exceeded the timeout
186187
if time.Now().After(deadline) {

cmd/bundle/generate/alert.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/base64"
55
"errors"
66
"fmt"
7+
"net/http"
78
"os"
89
"path"
910
"path/filepath"
@@ -81,7 +82,7 @@ After generation, you can deploy this alert to other targets using:
8182
if err != nil {
8283
// Check if it's a not found error to provide a better message
8384
var apiErr *apierr.APIError
84-
if errors.As(err, &apiErr) && apiErr.StatusCode == 404 {
85+
if errors.As(err, &apiErr) && apiErr.StatusCode == http.StatusNotFound {
8586
return fmt.Errorf("alert with ID %s not found", alertID)
8687
}
8788
return err

cmd/labs/github/github.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ func getPagedBytes(ctx context.Context, method, url string, body io.Reader) (*pa
5656
url = strings.Replace(url, gitHubUserContent, uco, 1)
5757
}
5858
log.Tracef(ctx, "%s %s", method, url)
59-
req, err := http.NewRequestWithContext(ctx, "GET", url, body)
59+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, body)
6060
if err != nil {
6161
return nil, err
6262
}
6363
res, err := http.DefaultClient.Do(req)
6464
if err != nil {
6565
return nil, err
6666
}
67-
if res.StatusCode == 404 {
67+
if res.StatusCode == http.StatusNotFound {
6868
return nil, ErrNotFound
6969
}
7070
if res.StatusCode >= 400 {

experimental/ssh/internal/client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ func getServerMetadata(ctx context.Context, client *databricks.WorkspaceClient,
439439
}
440440
metadataURL := fmt.Sprintf("%s/driver-proxy-api/o/%d/%s/%d/metadata", client.Config.Host, workspaceID, effectiveClusterID, wsMetadata.Port)
441441
log.Debugf(ctx, "Metadata URL: %s", metadataURL)
442-
req, err := http.NewRequestWithContext(ctx, "GET", metadataURL, nil)
442+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, metadataURL, nil)
443443
if err != nil {
444444
return 0, "", "", err
445445
}

experimental/ssh/internal/client/websockets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func createWebsocketConnection(ctx context.Context, client *databricks.Workspace
1515
return nil, fmt.Errorf("failed to get proxy URL: %w", err)
1616
}
1717

18-
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
18+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
1919
if err != nil {
2020
return nil, fmt.Errorf("failed to create request: %w", err)
2121
}

libs/appproxy/appproxy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const (
1919
)
2020

2121
func sendTestRequest(t *testing.T, url, path string) (int, []byte) {
22-
req, err := http.NewRequest("GET", url+path, bytes.NewBufferString("{'test': 'value'}"))
22+
req, err := http.NewRequest(http.MethodGet, url+path, bytes.NewBufferString("{'test': 'value'}"))
2323
require.NoError(t, err)
2424
req.Header.Set("Content-Type", "application/json")
2525

libs/apps/vite/bridge.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func NewBridge(ctx context.Context, w *databricks.WorkspaceClient, appName strin
133133
}
134134

135135
func (vb *Bridge) getAuthHeaders(wsURL string) (http.Header, error) {
136-
req, err := http.NewRequestWithContext(vb.ctx, "GET", wsURL, nil)
136+
req, err := http.NewRequestWithContext(vb.ctx, http.MethodGet, wsURL, nil)
137137
if err != nil {
138138
return nil, fmt.Errorf("failed to create request: %w", err)
139139
}

libs/auth/credentials_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func TestCLICredentialsConfigure(t *testing.T) {
176176
}
177177

178178
// Verify the credentials provider sets the correct Bearer token.
179-
req, err := http.NewRequest("GET", tt.cfg.Host, nil)
179+
req, err := http.NewRequest(http.MethodGet, tt.cfg.Host, nil)
180180
if err != nil {
181181
t.Fatalf("creating request: %v", err)
182182
}

libs/testproxy/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func New(t testutil.TestingT) *ProxyServer {
6262
func (s *ProxyServer) reqBody(r testserver.Request) any {
6363
// The SDK expects the query parameters to be specified in the "request body"
6464
// argument for GET, DELETE, and HEAD requests in the .Do method.
65-
if r.Method == "GET" || r.Method == "DELETE" || r.Method == "HEAD" {
65+
if r.Method == http.MethodGet || r.Method == http.MethodDelete || r.Method == http.MethodHead {
6666
queryParams := make(map[string]any)
6767
for k, v := range r.URL.Query() {
6868
queryParams[k] = v[0]

0 commit comments

Comments
 (0)