Skip to content

Commit 1ceb87e

Browse files
committed
linters
1 parent 1a5821b commit 1ceb87e

File tree

18 files changed

+68
-150
lines changed

18 files changed

+68
-150
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
uses: golangci/golangci-lint-action@v2
1313
with:
1414
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
15-
version: v1.59
15+
version: v1.63.4
1616

1717
# Optional: working directory, useful for monorepos
1818
# working-directory: somedir

.golangci.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ linters-settings:
2020
excludes:
2121
- G108
2222
- G114
23+
- G115
2324
revive:
2425
rules:
2526
- name: unused-parameter
@@ -33,16 +34,17 @@ linters-settings:
3334
- github.com/getsentry/sentry-go
3435
- github.com/gin-gonic/gin
3536
- github.com/nikandfor/assert
36-
- github.com/nikandfor/hacked
3737
- github.com/opentracing/opentracing-go
3838
- github.com/prometheus/client_golang
3939
- github.com/prometheus/client_model
4040
- github.com/stretchr/testify/assert
4141
- github.com/stretchr/testify/require
4242
- go.opentelemetry.io/otel
4343
- golang.org/x
44+
- nikand.dev/go/cbor
4445
- nikand.dev/go/cli
4546
- nikand.dev/go/graceful
47+
- nikand.dev/go/hacked
4648
- tlog.app/go/eazy
4749
- tlog.app/go/errors
4850
- tlog.app/go/loc
@@ -74,6 +76,8 @@ linters:
7476
enable-all: true
7577
disable:
7678
- cyclop
79+
- dogsled
80+
- err113
7781
- exhaustive
7882
- exhaustivestruct
7983
- exhaustruct
@@ -86,15 +90,16 @@ linters:
8690
- goconst
8791
- gocyclo
8892
- godox
89-
- err113
9093
- golint
9194
- gomnd
92-
- mnd
95+
- gosmopolitan
9396
- ifshort
97+
- inamedparam
9498
- ireturn
9599
- lll
96100
- maintidx
97101
- maligned
102+
- mnd
98103
- nakedret
99104
- nestif
100105
- nlreturn
@@ -103,6 +108,9 @@ linters:
103108
- paralleltest
104109
- prealloc
105110
- predeclared
111+
- recvcheck
112+
- tagalign
113+
- testifylint
106114
- testpackage
107115
- thelper
108116
- typecheck

agent/agent.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type (
3030
subs []sub
3131

3232
streams []*stream
33-
files []*file
33+
// files []*file
3434

3535
// end of mu
3636

@@ -202,7 +202,7 @@ func (a *Agent) writeFile(s *stream, f *file, p []byte, ts int64) (n int, err er
202202
tlog.Printw("write message", "i", geti(p))
203203

204204
s.zbuf = s.zbuf[:0]
205-
n, err = s.z.Write(p)
205+
_, err = s.z.Write(p)
206206
if err != nil {
207207
return 0, errors.Wrap(err, "eazy")
208208
}
@@ -248,7 +248,7 @@ func (a *Agent) writeFile(s *stream, f *file, p []byte, ts int64) (n int, err er
248248

249249
if s.boff == 0 {
250250
s.zbuf = s.zbuf[:0]
251-
n, err = s.z.Write(p)
251+
_, err = s.z.Write(p)
252252
if err != nil {
253253
return 0, errors.Wrap(err, "eazy")
254254
}
@@ -307,13 +307,13 @@ func (a *Agent) newFile(s *stream, part, ts int64) (*file, error) {
307307
}
308308

309309
func (a *Agent) padFile(s *stream, f *file) error {
310-
if f.off%int64(a.BlockSize) == 0 {
310+
if f.off%a.BlockSize == 0 {
311311
s.boff = 0
312312

313313
return nil
314314
}
315315

316-
off := f.off + int64(a.BlockSize) - f.off%int64(a.BlockSize)
316+
off := f.off + a.BlockSize - f.off%a.BlockSize
317317

318318
if s, ok := f.w.(interface {
319319
Truncate(int64) error

console.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -726,14 +726,15 @@ func (w *ConsoleWriter) ConvertValue(b, p []byte, st, ff int) (_ []byte, i int)
726726
}
727727
}
728728

729-
if quote && haveQuotes && !haveBackQuotes && w.QuoteUseBackQuotes {
729+
switch {
730+
case quote && haveQuotes && !haveBackQuotes && w.QuoteUseBackQuotes:
730731
b = append(b, '`')
731732
b = append(b, s...)
732733
b = append(b, '`')
733-
} else if quote {
734+
case quote:
734735
ss := tlow.UnsafeBytesToString(s)
735736
b = strconv.AppendQuote(b, ss)
736-
} else {
737+
default:
737738
b = append(b, s...)
738739
}
739740

@@ -918,6 +919,7 @@ func (w *ConsoleWriter) AppendDuration(b []byte, d time.Duration) []byte {
918919
d = add(d, time.Hour, 'h')
919920
d = add(d, time.Minute, 'm')
920921
d = add(d, time.Second, 's')
922+
_ = d
921923

922924
return append(b, buf[:i]...)
923925
}

convert/json.go

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -253,26 +253,7 @@ func (w *JSON) ConvertValue(b, p []byte, st int) (_ []byte, i int) {
253253

254254
id.FormatTo(b, bst, 'u')
255255
case tlwire.Caller:
256-
var pc loc.PC
257-
var pcs loc.PCs
258-
pc, pcs, i = w.d.Callers(p, st)
259-
260-
if pcs != nil {
261-
b = append(b, '[')
262-
for i, pc := range pcs {
263-
if i != 0 {
264-
b = append(b, ',')
265-
}
266-
267-
_, file, line := pc.NameFileLine()
268-
b = fmt.Appendf(b, `"%v:%d"`, filepath.Base(file), line)
269-
}
270-
b = append(b, ']')
271-
} else {
272-
_, file, line := pc.NameFileLine()
273-
274-
b = fmt.Appendf(b, `"%v:%d"`, filepath.Base(file), line)
275-
}
256+
b, i = appendCallers(b, p, st, w.d)
276257
default:
277258
b, i = w.ConvertValue(b, p, i)
278259
}
@@ -337,3 +318,28 @@ func (r SimpleRenamer) fallback(b, p, k []byte, i int) ([]byte, bool) {
337318

338319
return r.Fallback(b, p, k, i)
339320
}
321+
322+
func appendCallers(b, p []byte, st int, d tlwire.Decoder) ([]byte, int) {
323+
var pc loc.PC
324+
var pcs loc.PCs
325+
pc, pcs, i := d.Callers(p, st)
326+
327+
if pcs != nil {
328+
b = append(b, '[')
329+
for i, pc := range pcs {
330+
if i != 0 {
331+
b = append(b, ',')
332+
}
333+
334+
_, file, line := pc.NameFileLine()
335+
b = fmt.Appendf(b, `"%v:%d"`, filepath.Base(file), line)
336+
}
337+
b = append(b, ']')
338+
} else {
339+
_, file, line := pc.NameFileLine()
340+
341+
b = fmt.Appendf(b, `"%v:%d"`, filepath.Base(file), line)
342+
}
343+
344+
return b, i
345+
}

convert/logfmt.go

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import (
44
"errors"
55
"fmt"
66
"io"
7-
"path/filepath"
87
"strconv"
98
"time"
109

1110
"golang.org/x/term"
1211
"nikand.dev/go/hacked/low"
13-
"tlog.app/go/loc"
1412

1513
"tlog.app/go/tlog"
1614
tlow "tlog.app/go/tlog/low"
@@ -259,26 +257,7 @@ func (w *Logfmt) ConvertValue(b, p, k []byte, st int) (_ []byte, i int) {
259257

260258
id.FormatTo(b, bst, 'u')
261259
case tlwire.Caller:
262-
var pc loc.PC
263-
var pcs loc.PCs
264-
pc, pcs, i = w.d.Callers(p, st)
265-
266-
if pcs != nil {
267-
b = append(b, '[')
268-
for i, pc := range pcs {
269-
if i != 0 {
270-
b = append(b, ',')
271-
}
272-
273-
_, file, line := pc.NameFileLine()
274-
b = fmt.Appendf(b, `"%v:%d"`, filepath.Base(file), line)
275-
}
276-
b = append(b, ']')
277-
} else {
278-
_, file, line := pc.NameFileLine()
279-
280-
b = fmt.Appendf(b, `"%v:%d"`, filepath.Base(file), line)
281-
}
260+
b, i = appendCallers(b, p, st, w.d)
282261
default:
283262
b, i = w.ConvertValue(b, p, k, i)
284263
}

convert/logfmt_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"testing"
77
"time"
88

9-
"nikand.dev/go/hacked/low"
109
"github.com/stretchr/testify/assert"
10+
"nikand.dev/go/hacked/low"
1111

1212
"tlog.app/go/tlog"
1313
"tlog.app/go/tlog/tlwire"

convert/web.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,9 @@ type (
2525
PickMessage bool
2626

2727
d tlwire.Decoder
28-
l Logfmt
29-
j JSON
3028
c *tlog.ConsoleWriter
3129

3230
s []tlog.ID
33-
m []byte
3431

3532
time, last []byte
3633

ext/tlflag/flag_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ func TestURLWriter(t *testing.T) { //nolint:dupl
113113
func TestRotatedWriter(t *testing.T) {
114114
OpenFileWriter = TestingFileOpener
115115

116-
const CompressorBlockSize = 1 * eazy.MiB
117-
118116
with := func(f *rotating.File, wrap func(*rotating.File)) *rotating.File {
119117
wrap(f)
120118

id_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestIDJSON(t *testing.T) {
4242
data, err := json.Marshal(id)
4343
assert.NoError(t, err)
4444

45-
t.Logf("json encoded id: %s (% x)", data, []byte(id[:]))
45+
t.Logf("json encoded id: %s (% x)", data, id[:])
4646

4747
var back ID
4848
err = json.Unmarshal(data, &back)

rotating/ctime_darwin.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ import (
66
"time"
77
)
88

9-
func fileCtime(fstat func(string) (fs.FileInfo, error), name string, now time.Time) time.Time {
10-
inf, err := fstat(name)
11-
if err != nil {
12-
return now
13-
}
14-
15-
return ctime(inf, now)
16-
}
17-
189
func ctime(inf fs.FileInfo, now time.Time) time.Time {
1910
stat, ok := inf.Sys().(*syscall.Stat_t)
2011
if !ok {

rotating/ctime_linux.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ import (
66
"time"
77
)
88

9-
func fileCtime(fstat func(string) (fs.FileInfo, error), name string, now time.Time) time.Time {
10-
inf, err := fstat(name)
11-
if err != nil {
12-
return now
13-
}
14-
15-
return ctime(inf, now)
16-
}
17-
189
func ctime(inf fs.FileInfo, now time.Time) time.Time {
1910
stat, ok := inf.Sys().(*syscall.Stat_t)
2011
if !ok {

rotating/ctime_windows.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@ import (
66
"time"
77
)
88

9-
func fileCtime(fstat func(string) (fs.FileInfo, error), name string, now time.Time) time.Time {
10-
inf, err := fstat(name)
11-
if err != nil {
12-
return now
13-
}
14-
15-
return ctime(inf, now)
16-
}
17-
189
func ctime(inf fs.FileInfo, now time.Time) time.Time {
1910
stat, ok := inf.Sys().(*syscall.Win32FileAttributeData)
2011
if !ok {

rotating/file.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (f *File) Write(p []byte) (n int, err error) {
110110

111111
if f.w == nil || f.size != 0 &&
112112
(f.MaxFileSize != 0 && f.size+int64(len(p)) > f.MaxFileSize ||
113-
f.MaxFileAge != 0 && time.Since(f.start) > f.MaxFileAge) {
113+
f.MaxFileAge != 0 && time.Since(f.start) > f.MaxFileAge) { //nolint:whitespace
114114

115115
err = f.rotate()
116116
if err != nil {
@@ -163,7 +163,6 @@ func (f *File) rotate() (err error) {
163163
f.current = fname
164164
f.size = 0
165165
f.start = now
166-
// f.start = fileCtime(f.fstat, fname, now)
167166

168167
if f.symlink != nil {
169168
link := filepath.Join(f.dir, f.pref+"LATEST"+f.suff)
@@ -173,7 +172,9 @@ func (f *File) rotate() (err error) {
173172
}
174173

175174
if f.MaxTotalSize != 0 || f.MaxTotalAge != 0 || f.MaxTotalFiles != 0 {
176-
go f.removeOld(f.dir, base, f.pref, f.suff, f.format, f.start)
175+
go func(start time.Time) {
176+
_ = f.removeOld(f.dir, base, f.pref, f.suff, f.format, start)
177+
}(f.start)
177178
}
178179

179180
return

tlio/writers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type (
6363

6464
WriterFunc func(p []byte) (int, error)
6565

66-
// base interfaces
66+
// Base interfaces.
6767

6868
Flusher interface {
6969
Flush() error

tlog.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ func (s Span) IOWriter(d int) io.Writer {
441441
}
442442

443443
func (l *Logger) DumpWriter(d int, msg, key string) io.Writer {
444-
return dumpWrapper{
444+
return &dumpWrapper{
445445
Span: Span{
446446
Logger: l,
447447
},
@@ -453,7 +453,7 @@ func (l *Logger) DumpWriter(d int, msg, key string) io.Writer {
453453
}
454454

455455
func (s Span) DumpWriter(d int, msg, key string) io.Writer {
456-
return dumpWrapper{
456+
return &dumpWrapper{
457457
Span: s,
458458

459459
loc: loc.Caller(1 + d),
@@ -468,7 +468,7 @@ func (w writeWrapper) Write(p []byte) (int, error) {
468468
return len(p), nil
469469
}
470470

471-
func (w dumpWrapper) Write(p []byte) (int, error) {
471+
func (w *dumpWrapper) Write(p []byte) (int, error) {
472472
message(w.Logger, w.ID, -1, w.msg, []any{KeyCaller, w.loc, w.key, p})
473473

474474
return len(p), nil

0 commit comments

Comments
 (0)