From db54166991304220303ee1de8e06292c4c0a4e3c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 1 Jan 2023 17:41:03 -0700 Subject: lint: Turn on containedctx --- lib/textui/progress.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/textui') diff --git a/lib/textui/progress.go b/lib/textui/progress.go index 7b3f63a..56fda96 100644 --- a/lib/textui/progress.go +++ b/lib/textui/progress.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -19,7 +19,7 @@ type Stats interface { } type Progress[T Stats] struct { - ctx context.Context + ctx context.Context //nolint:containedctx // captured for separate goroutine lvl dlog.LogLevel interval time.Duration -- cgit v1.2.3-2-g168b From b6ec0ce387b0a3d9fb6f58ba43ca27943f99fb93 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 1 Jan 2023 17:41:53 -0700 Subject: lint: Turn on dogsled --- lib/textui/log.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/textui') diff --git a/lib/textui/log.go b/lib/textui/log.go index 5ddc7a8..bc8b159 100644 --- a/lib/textui/log.go +++ b/lib/textui/log.go @@ -1,5 +1,5 @@ // Copyright (C) 2019-2022 Ambassador Labs -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: Apache-2.0 // @@ -159,6 +159,7 @@ var ( ) func init() { + //nolint:dogsled // I can't change the signature of the stdlib. _, file, _, _ := runtime.Caller(0) thisModDir = filepath.Dir(filepath.Dir(filepath.Dir(file))) } -- cgit v1.2.3-2-g168b From 1faafcd3809fe5b452a1a742137ca2cb7336aad6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 1 Jan 2023 17:39:11 -0700 Subject: lint: Turn on dupword --- lib/textui/log.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/textui') diff --git a/lib/textui/log.go b/lib/textui/log.go index bc8b159..0fe03e5 100644 --- a/lib/textui/log.go +++ b/lib/textui/log.go @@ -172,8 +172,8 @@ func (l *logger) log(lvl dlog.LogLevel, writeMsg func(io.Writer)) { // This is optimized for mostly-single-threaded usage. If I cared more // about multi-threaded performance, I'd trade in some // memory-use/allocations and (1) instead of using a static `logBuf`, - // I'd have a `logBufPool` `sync.Pool`, and (2) have the the final call - // to `l.out.Write()` be the only thing protected by `logMu`. + // I'd have a `logBufPool` `sync.Pool`, and (2) have the final call to + // `l.out.Write()` be the only thing protected by `logMu`. logMu.Lock() defer logMu.Unlock() defer logBuf.Reset() -- cgit v1.2.3-2-g168b From 493ec396fab32d9e8859e34ad497fdb0a910a33c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 1 Jan 2023 17:49:11 -0700 Subject: lint: Turn on forcetypeassert --- lib/textui/progress.go | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/textui') diff --git a/lib/textui/progress.go b/lib/textui/progress.go index 56fda96..68d986f 100644 --- a/lib/textui/progress.go +++ b/lib/textui/progress.go @@ -56,6 +56,7 @@ func (p *Progress[T]) Done() { } func (p *Progress[T]) flush(force bool) { + //nolint:forcetypeassert // It wasn't worth it to me (yet?) to make a typed wrapper around atomic.Value. cur := p.cur.Load().(T) if !force && cur == p.oldStat { return -- cgit v1.2.3-2-g168b From a06a7fb2d5bbf1ca5659de06fc9e975666bdcf9f Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 1 Jan 2023 19:33:03 -0700 Subject: lint: Turn on gofumpt All edits to .go files are made by `tools/bin/golangci-lint run --fix ./...`, not by me as a human. --- lib/textui/text.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib/textui') diff --git a/lib/textui/text.go b/lib/textui/text.go index d6a80b3..615516d 100644 --- a/lib/textui/text.go +++ b/lib/textui/text.go @@ -72,9 +72,7 @@ type Portion[T constraints.Integer] struct { N, D T } -var ( - _ fmt.Stringer = Portion[int]{} -) +var _ fmt.Stringer = Portion[int]{} // String implements fmt.Stringer. func (p Portion[T]) String() string { -- cgit v1.2.3-2-g168b From b261c2a4f5f028c9d83cef208ccc7d829f841bad Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 31 Dec 2022 11:59:09 -0700 Subject: tree-wide: Annotate values that I might want to be tuning --- lib/textui/log_memstats.go | 2 +- lib/textui/tunable.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 lib/textui/tunable.go (limited to 'lib/textui') diff --git a/lib/textui/log_memstats.go b/lib/textui/log_memstats.go index 39733c6..6e3c3a1 100644 --- a/lib/textui/log_memstats.go +++ b/lib/textui/log_memstats.go @@ -19,7 +19,7 @@ type LiveMemUse struct { var _ fmt.Stringer = (*LiveMemUse)(nil) -const liveMemUseUpdateInterval = 1 * time.Second +var liveMemUseUpdateInterval = Tunable(1 * time.Second) func (o *LiveMemUse) String() string { o.mu.Lock() diff --git a/lib/textui/tunable.go b/lib/textui/tunable.go new file mode 100644 index 0000000..7e5f311 --- /dev/null +++ b/lib/textui/tunable.go @@ -0,0 +1,13 @@ +// Copyright (C) 2022 Luke Shumaker +// +// SPDX-License-Identifier: GPL-2.0-or-later + +package textui + +// Tunable annotates a value as something that might want to be tuned +// as the program gets optimized. +// +// TODO(lukeshu): Have Tunable be runtime-configurable. +func Tunable[T any](x T) T { + return x +} -- cgit v1.2.3-2-g168b From 5edd0d7be38595c4777d5130ca20f907d8a74963 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 1 Jan 2023 21:12:41 -0700 Subject: lint: Turn on paralleltest --- lib/textui/log_test.go | 5 ++++- lib/textui/text_test.go | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/textui') diff --git a/lib/textui/log_test.go b/lib/textui/log_test.go index 08eb38c..514d96e 100644 --- a/lib/textui/log_test.go +++ b/lib/textui/log_test.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -20,6 +20,7 @@ func logLineRegexp(inner string) string { } func TestLogFormat(t *testing.T) { + t.Parallel() var out strings.Builder ctx := dlog.WithLogger(context.Background(), textui.NewLogger(&out, dlog.LogLevelTrace)) dlog.Debugf(ctx, "foo %d", 12345) @@ -29,6 +30,7 @@ func TestLogFormat(t *testing.T) { } func TestLogLevel(t *testing.T) { + t.Parallel() var out strings.Builder ctx := dlog.WithLogger(context.Background(), textui.NewLogger(&out, dlog.LogLevelInfo)) dlog.Error(ctx, "Error") @@ -54,6 +56,7 @@ func TestLogLevel(t *testing.T) { } func TestLogField(t *testing.T) { + t.Parallel() var out strings.Builder ctx := dlog.WithLogger(context.Background(), textui.NewLogger(&out, dlog.LogLevelInfo)) ctx = dlog.WithField(ctx, "foo", 12345) diff --git a/lib/textui/text_test.go b/lib/textui/text_test.go index c4b42f6..4b93683 100644 --- a/lib/textui/text_test.go +++ b/lib/textui/text_test.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -16,12 +16,14 @@ import ( ) func TestFprintf(t *testing.T) { + t.Parallel() var out strings.Builder textui.Fprintf(&out, "%d", 12345) assert.Equal(t, "12,345", out.String()) } func TestHumanized(t *testing.T) { + t.Parallel() assert.Equal(t, "12,345", fmt.Sprint(textui.Humanized(12345))) assert.Equal(t, "12,345 ", fmt.Sprintf("%-8d", textui.Humanized(12345))) @@ -32,6 +34,7 @@ func TestHumanized(t *testing.T) { } func TestPortion(t *testing.T) { + t.Parallel() assert.Equal(t, "100% (0/0)", fmt.Sprint(textui.Portion[int]{})) assert.Equal(t, "0% (1/12,345)", fmt.Sprint(textui.Portion[int]{N: 1, D: 12345})) assert.Equal(t, "100% (0/0)", fmt.Sprint(textui.Portion[btrfsvol.PhysicalAddr]{})) -- cgit v1.2.3-2-g168b From 6e1a9fbb1e9a943e04902ed3a4958f6821e39456 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 1 Jan 2023 22:41:34 -0700 Subject: lint: Set exclude-use-default=false --- lib/textui/log.go | 8 ++++---- lib/textui/text.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'lib/textui') diff --git a/lib/textui/log.go b/lib/textui/log.go index 0fe03e5..d2373f8 100644 --- a/lib/textui/log.go +++ b/lib/textui/log.go @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2022 Ambassador Labs +// Copyright (C) 2019-2022-2023 Ambassador Labs // Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: Apache-2.0 @@ -134,21 +134,21 @@ func (l *logger) Log(lvl dlog.LogLevel, msg string) { // UnformattedLog implements dlog.OptimizedLogger. func (l *logger) UnformattedLog(lvl dlog.LogLevel, args ...any) { l.log(lvl, func(w io.Writer) { - printer.Fprint(w, args...) + _, _ = printer.Fprint(w, args...) }) } // UnformattedLogln implements dlog.OptimizedLogger. func (l *logger) UnformattedLogln(lvl dlog.LogLevel, args ...any) { l.log(lvl, func(w io.Writer) { - printer.Fprintln(w, args...) + _, _ = printer.Fprintln(w, args...) }) } // UnformattedLogf implements dlog.OptimizedLogger. func (l *logger) UnformattedLogf(lvl dlog.LogLevel, format string, args ...any) { l.log(lvl, func(w io.Writer) { - printer.Fprintf(w, format, args...) + _, _ = printer.Fprintf(w, format, args...) }) } diff --git a/lib/textui/text.go b/lib/textui/text.go index 615516d..c0a3c5e 100644 --- a/lib/textui/text.go +++ b/lib/textui/text.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -53,7 +53,7 @@ var ( // String implements fmt.Formatter. func (h humanized) Format(f fmt.State, verb rune) { - printer.Fprintf(f, fmtutil.FmtStateString(f, verb), h.val) + _, _ = printer.Fprintf(f, fmtutil.FmtStateString(f, verb), h.val) } // String implements fmt.Stringer. @@ -144,7 +144,7 @@ func (v metric[T]) Format(f fmt.State, verb rune) { if v.Val < 0 { y = -y } - printer.Fprintf(f, fmtutil.FmtStateString(f, verb)+"%s%s", + _, _ = printer.Fprintf(f, fmtutil.FmtStateString(f, verb)+"%s%s", y, prefix, v.Unit) } @@ -192,7 +192,7 @@ func (v iec[T]) Format(f fmt.State, verb rune) { if v.Val < 0 { y = -y } - printer.Fprintf(f, fmtutil.FmtStateString(f, verb)+"%s%s", + _, _ = printer.Fprintf(f, fmtutil.FmtStateString(f, verb)+"%s%s", number.Decimal(y), prefix, v.Unit) } -- cgit v1.2.3-2-g168b