Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support slog.Group function #63

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sloglint.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ var slogFuncs = map[string]struct {
"log/slog.InfoContext": {argsPos: 2},
"log/slog.WarnContext": {argsPos: 2},
"log/slog.ErrorContext": {argsPos: 2},
"log/slog.Group": {argsPos: 1},
"(*log/slog.Logger).With": {argsPos: 0, skipContextCheck: true},
"(*log/slog.Logger).Log": {argsPos: 3},
"(*log/slog.Logger).LogAttrs": {argsPos: 3},
Expand Down
2 changes: 2 additions & 0 deletions testdata/src/kv_only/kv_only.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ func tests() {
slog.Info("msg", "foo", 1, "bar", 2)
slog.With("foo", 1).Info("msg")
slog.With("foo", 1, "bar", 2).Info("msg")
slog.Group("group", "foo", 1, "baz", 2)

slog.Info("msg", slog.Int("foo", 1)) // want `attributes should not be used`
slog.Info("msg", slog.Int("foo", 1), slog.Int("bar", 2)) // want `attributes should not be used`
slog.Info("msg", "foo", 1, slog.Int("bar", 2)) // want `attributes should not be used`
slog.With(slog.Int("foo", 1)).Info("msg") // want `attributes should not be used`
slog.With(slog.Int("foo", 1), slog.Int("bar", 2)).Info("msg") // want `attributes should not be used`
slog.With("foo", 1, slog.Int("bar", 2)).Info("msg") // want `attributes should not be used`
slog.Group("group", slog.String("foo", "1")) // want `attributes should not be used`

args := []any{"foo", 1, "bar", 2}
slog.Log(nil, slog.LevelInfo, "msg", args...)
Expand Down
3 changes: 3 additions & 0 deletions testdata/src/no_mixed_args/no_mixed_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func tests() {
slog.With("foo", 1, "bar", 2).Info("msg")
slog.With(slog.Int("foo", 1)).Info("msg")
slog.With(slog.Int("foo", 1), slog.Int("bar", 2)).Info("msg")
slog.Group("group", "foo", 1, "baz", 2)
slog.Group("group", slog.String("foo", "1"))

slog.Log(ctx, slog.LevelInfo, "msg", "foo", 1, slog.Int("bar", 2)) // want `key-value pairs and attributes should not be mixed`
slog.Debug("msg", "foo", 1, slog.Int("bar", 2)) // want `key-value pairs and attributes should not be mixed`
Expand All @@ -28,6 +30,7 @@ func tests() {
slog.WarnContext(ctx, "msg", "foo", 1, slog.Int("bar", 2)) // want `key-value pairs and attributes should not be mixed`
slog.ErrorContext(ctx, "msg", "foo", 1, slog.Int("bar", 2)) // want `key-value pairs and attributes should not be mixed`
slog.With("foo", 1, slog.Int("bar", 2)).ErrorContext(ctx, "msg") // want `key-value pairs and attributes should not be mixed`
slog.Group("group", slog.String("foo", "1"), "baz", 2) // want `key-value pairs and attributes should not be mixed`

logger.Log(ctx, slog.LevelInfo, "msg", "foo", 1, slog.Int("bar", 2)) // want `key-value pairs and attributes should not be mixed`
logger.Debug("msg", "foo", 1, slog.Int("bar", 2)) // want `key-value pairs and attributes should not be mixed`
Expand Down
Loading