From 73b4ffade849253d44907d01be852398a6292cc4 Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Mon, 13 Apr 2026 23:50:22 +0200 Subject: [PATCH] Add lint rule to prevent use of stdlib `log` package Add a depguard rule that blocks `import "log"` and nudges towards `libs/log` instead. Migrate the single existing violation in `libs/appproxy`. Build tools (`docsgen`, `schema`, `validation`) are excluded. Co-authored-by: Isaac --- .golangci.yaml | 9 +++++++++ libs/appproxy/appproxy.go | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index e64590f365..9bc6c5d1ac 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -34,6 +34,15 @@ linters: deny: - pkg: "github.com/databricks/cli/experimental" desc: "must not import experimental/ packages; use an interface or move the dependency" + no-stdlib-log: + files: + - "**" + - "!**/bundle/docsgen/**" + - "!**/bundle/internal/schema/**" + - "!**/bundle/internal/validation/**" + deny: + - pkg: "log$" + desc: "use libs/log instead of the standard library log package" forbidigo: forbid: - pattern: 'term\.IsTerminal' diff --git a/libs/appproxy/appproxy.go b/libs/appproxy/appproxy.go index a1b4adfc68..d1d7c5c9df 100644 --- a/libs/appproxy/appproxy.go +++ b/libs/appproxy/appproxy.go @@ -3,11 +3,12 @@ package appproxy import ( "context" "io" - "log" "net" "net/http" "net/url" "strings" + + "github.com/databricks/cli/libs/log" ) type Proxy struct { @@ -122,7 +123,7 @@ func (p *Proxy) handleWebSocket(w http.ResponseWriter, r *http.Request) { // If the error is not EOF, then there was a problem if err != io.EOF { // Log the error and perform cleanup - log.Printf("Error copying messages: %v", err) + log.Warnf(r.Context(), "error copying messages: %v", err) middlewareConn.Close() targetServerConn.Close() }