Skip to content

Commit

Permalink
Fix some lint
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Dec 2, 2023
1 parent b7296bb commit 8d309b3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
# version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# version of Go to use
go-version: '1.21'

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

Expand Down
22 changes: 11 additions & 11 deletions sloghandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (l *slogHandler) GetLevel() slog.Level {
return l.levelBias
}

func (l *slogHandler) Enabled(ctx context.Context, level slog.Level) bool {
func (l *slogHandler) Enabled(_ context.Context, level slog.Level) bool {
return l.sink != nil && (level >= slog.LevelError || l.sink.Enabled(l.levelFromSlog(level)))
}

Expand Down Expand Up @@ -107,34 +107,34 @@ func (l *slogHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
return l
}

copy := *l
clone := *l
if l.slogSink != nil {
copy.slogSink = l.slogSink.WithAttrs(attrs)
copy.sink = copy.slogSink
clone.slogSink = l.slogSink.WithAttrs(attrs)
clone.sink = clone.slogSink
} else {
kvList := make([]any, 0, 2*len(attrs))
for _, attr := range attrs {
if attr.Key != "" {
kvList = append(kvList, l.addGroupPrefix(attr.Key), attr.Value.Resolve().Any())
}
}
copy.sink = l.sink.WithValues(kvList...)
clone.sink = l.sink.WithValues(kvList...)
}
return &copy
return &clone
}

func (l *slogHandler) WithGroup(name string) slog.Handler {
if l.sink == nil {
return l
}
copy := *l
clone := *l
if l.slogSink != nil {
copy.slogSink = l.slogSink.WithGroup(name)
copy.sink = copy.slogSink
clone.slogSink = l.slogSink.WithGroup(name)
clone.sink = clone.slogSink
} else {
copy.groupPrefix = copy.addGroupPrefix(name)
clone.groupPrefix = clone.addGroupPrefix(name)
}
return &copy
return &clone
}

func (l *slogHandler) addGroupPrefix(name string) string {
Expand Down
3 changes: 2 additions & 1 deletion slogr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ func containsOne(hay string, needles ...string) bool {
return false
}

func TestDiscard(t *testing.T) {
func TestDiscard(_ *testing.T) {
// Compile-test
logger := slog.New(logr.ToSlogHandler(logr.Discard()))
logger.WithGroup("foo").With("x", 1).Info("hello")
}
Expand Down
4 changes: 2 additions & 2 deletions slogsink.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ func (l *slogSink) log(err error, msg string, level slog.Level, kvList ...interf
record.AddAttrs(slog.Any(errKey, err))
}
record.Add(kvList...)
l.handler.Handle(context.Background(), record)
_ = l.handler.Handle(context.Background(), record)
}

func (l slogSink) WithName(name string) LogSink {
if l.name != "" {
l.name = l.name + "/"
l.name += "/"
}
l.name += name
return &l
Expand Down

0 comments on commit 8d309b3

Please sign in to comment.