Skip to content

Commit 83dbe72

Browse files
committedDec 8, 2023
Fix some lint
1 parent b5e7d9f commit 83dbe72

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed
 

‎.github/workflows/lint.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ jobs:
1111
steps:
1212
- name: Checkout code
1313
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
14+
- name: Update Go
15+
uses: actions/setup-go@v4
16+
with:
17+
go-version: '>=1.21.0'
18+
cache: false
1419
- name: Lint
1520
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
1621
with:

‎sloghandler.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (l *slogHandler) GetLevel() slog.Level {
5252
return l.levelBias
5353
}
5454

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

@@ -107,20 +107,20 @@ func (l *slogHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
107107
return l
108108
}
109109

110-
copy := *l
110+
clone := *l
111111
if l.slogSink != nil {
112-
copy.slogSink = l.slogSink.WithAttrs(attrs)
113-
copy.sink = copy.slogSink
112+
clone.slogSink = l.slogSink.WithAttrs(attrs)
113+
clone.sink = clone.slogSink
114114
} else {
115115
kvList := make([]any, 0, 2*len(attrs))
116116
for _, attr := range attrs {
117117
if attr.Key != "" {
118118
kvList = append(kvList, l.addGroupPrefix(attr.Key), attr.Value.Resolve().Any())
119119
}
120120
}
121-
copy.sink = l.sink.WithValues(kvList...)
121+
clone.sink = l.sink.WithValues(kvList...)
122122
}
123-
return &copy
123+
return &clone
124124
}
125125

126126
func (l *slogHandler) WithGroup(name string) slog.Handler {
@@ -131,14 +131,14 @@ func (l *slogHandler) WithGroup(name string) slog.Handler {
131131
// slog says to inline empty groups
132132
return l
133133
}
134-
copy := *l
134+
clone := *l
135135
if l.slogSink != nil {
136-
copy.slogSink = l.slogSink.WithGroup(name)
137-
copy.sink = copy.slogSink
136+
clone.slogSink = l.slogSink.WithGroup(name)
137+
clone.sink = clone.slogSink
138138
} else {
139-
copy.groupPrefix = copy.addGroupPrefix(name)
139+
clone.groupPrefix = clone.addGroupPrefix(name)
140140
}
141-
return &copy
141+
return &clone
142142
}
143143

144144
func (l *slogHandler) addGroupPrefix(name string) string {

‎slogr_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ func containsOne(hay string, needles ...string) bool {
190190
return false
191191
}
192192

193-
func TestDiscard(t *testing.T) {
193+
func TestDiscard(_ *testing.T) {
194+
// Compile-test
194195
logger := slog.New(logr.ToSlogHandler(logr.Discard()))
195196
logger.WithGroup("foo").With("x", 1).Info("hello")
196197
}

‎slogsink.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ func (l *slogSink) log(err error, msg string, level slog.Level, kvList ...interf
9191
record.AddAttrs(slog.Any(errKey, err))
9292
}
9393
record.Add(kvList...)
94-
l.handler.Handle(context.Background(), record)
94+
_ = l.handler.Handle(context.Background(), record)
9595
}
9696

9797
func (l slogSink) WithName(name string) LogSink {
9898
if l.name != "" {
99-
l.name = l.name + "/"
99+
l.name += "/"
100100
}
101101
l.name += name
102102
return &l

0 commit comments

Comments
 (0)
Please sign in to comment.