[tools] go/analysis/passes/slog: replace XXXCtx names with XXXContext

154 views
Skip to first unread message

Jonathan Amsterdam (Gerrit)

unread,
Jul 6, 2023, 5:42:09 PM7/6/23
to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Alan Donovan, kokoro, Gopher Robot, Russ Cox, golang-co...@googlegroups.com

Jonathan Amsterdam submitted this change.

View Change

Approvals: Gopher Robot: TryBots succeeded Alan Donovan: Looks good to me, approved Jonathan Amsterdam: Run TryBots kokoro: gopls CI succeeded
go/analysis/passes/slog: replace XXXCtx names with XXXContext

Change-Id: I3ef32e6ad5a28d298a4b3536a414be058cf025fc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/508255
Run-TryBot: Jonathan Amsterdam <j...@google.com>
TryBot-Result: Gopher Robot <go...@golang.org>
gopls-CI: kokoro <noreply...@google.com>
Reviewed-by: Alan Donovan <adon...@google.com>
---
M go/analysis/passes/slog/slog.go
M go/analysis/passes/slog/slog_test.go
M go/analysis/passes/slog/testdata/src/a/a.go
3 files changed, 38 insertions(+), 37 deletions(-)

diff --git a/go/analysis/passes/slog/slog.go b/go/analysis/passes/slog/slog.go
index 8429eab..cdceac6 100644
--- a/go/analysis/passes/slog/slog.go
+++ b/go/analysis/passes/slog/slog.go
@@ -195,28 +195,28 @@
// The first key is the dereferenced receiver type name, or "" for a function.
var kvFuncs = map[string]map[string]int{
"": map[string]int{
- "Debug": 1,
- "Info": 1,
- "Warn": 1,
- "Error": 1,
- "DebugCtx": 2,
- "InfoCtx": 2,
- "WarnCtx": 2,
- "ErrorCtx": 2,
- "Log": 3,
- "Group": 1,
+ "Debug": 1,
+ "Info": 1,
+ "Warn": 1,
+ "Error": 1,
+ "DebugContext": 2,
+ "InfoContext": 2,
+ "WarnContext": 2,
+ "ErrorContext": 2,
+ "Log": 3,
+ "Group": 1,
},
"Logger": map[string]int{
- "Debug": 1,
- "Info": 1,
- "Warn": 1,
- "Error": 1,
- "DebugCtx": 2,
- "InfoCtx": 2,
- "WarnCtx": 2,
- "ErrorCtx": 2,
- "Log": 3,
- "With": 0,
+ "Debug": 1,
+ "Info": 1,
+ "Warn": 1,
+ "Error": 1,
+ "DebugContext": 2,
+ "InfoContext": 2,
+ "WarnContext": 2,
+ "ErrorContext": 2,
+ "Log": 3,
+ "With": 0,
},
"Record": map[string]int{
"Add": 0,
diff --git a/go/analysis/passes/slog/slog_test.go b/go/analysis/passes/slog/slog_test.go
index b64b256..094b39c 100644
--- a/go/analysis/passes/slog/slog_test.go
+++ b/go/analysis/passes/slog/slog_test.go
@@ -13,6 +13,7 @@
)

func Test(t *testing.T) {
+ t.Skip("skipping pending renaming of slog.XXXCtx functions in stdlib")
testenv.NeedsGo1Point(t, 21)
testdata := analysistest.TestData()
analysistest.Run(t, testdata, slog.Analyzer, "a", "b")
diff --git a/go/analysis/passes/slog/testdata/src/a/a.go b/go/analysis/passes/slog/testdata/src/a/a.go
index aa408d0..f1b3ec9 100644
--- a/go/analysis/passes/slog/testdata/src/a/a.go
+++ b/go/analysis/passes/slog/testdata/src/a/a.go
@@ -31,8 +31,8 @@
l.With("a", 1)
slog.Warn("msg", slog.Int("a", 1))
slog.Warn("msg", slog.Int("a", 1), "k", 2)
- l.WarnCtx(nil, "msg", "a", 1, slog.Int("b", 2), slog.Int("c", 3), "d", 4)
- l.DebugCtx(nil, "msg", "a", 1, slog.Int("b", 2), slog.Int("c", 3), "d", 4, slog.Int("e", 5))
+ l.WarnContext(nil, "msg", "a", 1, slog.Int("b", 2), slog.Int("c", 3), "d", 4)
+ l.DebugContext(nil, "msg", "a", 1, slog.Int("b", 2), slog.Int("c", 3), "d", 4, slog.Int("e", 5))
r.Add("a", 1, "b", 2)
(*slog.Logger).Debug(l, "msg", "a", 1, "b", 2)

@@ -40,13 +40,13 @@
r.Add(key, 1)

// bad
- slog.Info("msg", 1) // want `slog.Info arg "1" should be a string or a slog.Attr`
- l.Info("msg", 2) // want `slog.Logger.Info arg "2" should be a string or a slog.Attr`
- slog.Debug("msg", "a") // want `call to slog.Debug missing a final value`
- slog.Warn("msg", slog.Int("a", 1), "k") // want `call to slog.Warn missing a final value`
- slog.ErrorCtx(nil, "msg", "a", 1, "b") // want `call to slog.ErrorCtx missing a final value`
- r.Add("K", "v", "k") // want `call to slog.Record.Add missing a final value`
- l.With("a", "b", 2) // want `slog.Logger.With arg "2" should be a string or a slog.Attr`
+ slog.Info("msg", 1) // want `slog.Info arg "1" should be a string or a slog.Attr`
+ l.Info("msg", 2) // want `slog.Logger.Info arg "2" should be a string or a slog.Attr`
+ slog.Debug("msg", "a") // want `call to slog.Debug missing a final value`
+ slog.Warn("msg", slog.Int("a", 1), "k") // want `call to slog.Warn missing a final value`
+ slog.ErrorContext(nil, "msg", "a", 1, "b") // want `call to slog.ErrorContext missing a final value`
+ r.Add("K", "v", "k") // want `call to slog.Record.Add missing a final value`
+ l.With("a", "b", 2) // want `slog.Logger.With arg "2" should be a string or a slog.Attr`

// Report the first problem if there are multiple bad keys.
slog.Debug("msg", "a", 1, 2, 3, 4) // want `slog.Debug arg "2" should be a string or a slog.Attr`
@@ -120,10 +120,10 @@
slog.Info("msg", 1, 2) // want `slog.Info arg "1" should be a string or a slog.Attr`
slog.Warn("msg", 1, 2) // want `slog.Warn arg "1" should be a string or a slog.Attr`

- slog.DebugCtx(ctx, "msg", 1, 2) // want `slog.DebugCtx arg "1" should be a string or a slog.Attr`
- slog.ErrorCtx(ctx, "msg", 1, 2) // want `slog.ErrorCtx arg "1" should be a string or a slog.Attr`
- slog.InfoCtx(ctx, "msg", 1, 2) // want `slog.InfoCtx arg "1" should be a string or a slog.Attr`
- slog.WarnCtx(ctx, "msg", 1, 2) // want `slog.WarnCtx arg "1" should be a string or a slog.Attr`
+ slog.DebugContext(ctx, "msg", 1, 2) // want `slog.DebugContext arg "1" should be a string or a slog.Attr`
+ slog.ErrorContext(ctx, "msg", 1, 2) // want `slog.ErrorContext arg "1" should be a string or a slog.Attr`
+ slog.InfoContext(ctx, "msg", 1, 2) // want `slog.InfoContext arg "1" should be a string or a slog.Attr`
+ slog.WarnContext(ctx, "msg", 1, 2) // want `slog.WarnContext arg "1" should be a string or a slog.Attr`

slog.Log(ctx, slog.LevelDebug, "msg", 1, 2) // want `slog.Log arg "1" should be a string or a slog.Attr`

@@ -132,10 +132,10 @@
l.Info("msg", 1, 2) // want `slog.Logger.Info arg "1" should be a string or a slog.Attr`
l.Warn("msg", 1, 2) // want `slog.Logger.Warn arg "1" should be a string or a slog.Attr`

- l.DebugCtx(ctx, "msg", 1, 2) // want `slog.Logger.DebugCtx arg "1" should be a string or a slog.Attr`
- l.ErrorCtx(ctx, "msg", 1, 2) // want `slog.Logger.ErrorCtx arg "1" should be a string or a slog.Attr`
- l.InfoCtx(ctx, "msg", 1, 2) // want `slog.Logger.InfoCtx arg "1" should be a string or a slog.Attr`
- l.WarnCtx(ctx, "msg", 1, 2) // want `slog.Logger.WarnCtx arg "1" should be a string or a slog.Attr`
+ l.DebugContext(ctx, "msg", 1, 2) // want `slog.Logger.DebugContext arg "1" should be a string or a slog.Attr`
+ l.ErrorContext(ctx, "msg", 1, 2) // want `slog.Logger.ErrorContext arg "1" should be a string or a slog.Attr`
+ l.InfoContext(ctx, "msg", 1, 2) // want `slog.Logger.InfoContext arg "1" should be a string or a slog.Attr`
+ l.WarnContext(ctx, "msg", 1, 2) // want `slog.Logger.WarnContext arg "1" should be a string or a slog.Attr`

l.Log(ctx, slog.LevelDebug, "msg", 1, 2) // want `slog.Logger.Log arg "1" should be a string or a slog.Attr`


To view, visit change 508255. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I3ef32e6ad5a28d298a4b3536a414be058cf025fc
Gerrit-Change-Number: 508255
Gerrit-PatchSet: 4
Gerrit-Owner: Jonathan Amsterdam <j...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-Reviewer: kokoro <noreply...@google.com>
Gerrit-CC: kokoro <noreply...@google.com>
Reply all
Reply to author
Forward
0 new messages