Remediate all lint findings under the canonical golangci-lint config

Fix every finding surfaced by the canonical .golangci.yml with
golangci-lint v2.12.2 (refs #61), behavior-preserving throughout:

- err113: dynamic errors replaced with package-level sentinels and %w
  wrapping; direct comparisons converted to errors.Is
- goprintffuncname: printf-style helpers renamed with an f suffix
  (ui.Writer message methods, cli.ReportErrorf, database.Fatalf,
  vaultik stdoutf) and all call sites updated
- revive: stuttering type names renamed (blob.Handler, blob.WithReader,
  blob.ChunkPosition, storage.URL, storage.Info), doc comments added,
  unused parameters blanked, package comments added
- contextcheck/noctx: ctx threaded through blob.Packer
  (AddChunk/Flush/FinalizeBlob/PackChunks) and scanner call sites;
  context-aware exec and sql variants used
- funlen/cyclop/gocognit/nestif/dupl: oversized or duplicated
  functions split into focused helpers across production and test code
- paralleltest/tparallel/thelper/usetesting/testpackage: tests
  parallelized where safe (global log.Initialize kept in the serial
  phase), helpers marked, t.TempDir adopted, external test packages
  where only exported API is used
- gosec: integer conversions clamped or justified, header timeouts
  added, remaining findings suppressed with per-site justifications
- mnd/goconst/lll/wsl_v5/nlreturn/noinlineerr/errcheck and other
  mechanical findings fixed directly

Remove the deprecated log.LogOptions alias (callers migrated to
log.Options). make check is green.
This commit is contained in:
2026-08-07 18:51:21 +00:00
parent 6cf9211407
commit 7ae470e530
121 changed files with 8344 additions and 5406 deletions

View File

@@ -1,37 +1,45 @@
package ui
package ui_test
import (
"bytes"
"strings"
"testing"
"time"
"sneak.berlin/go/vaultik/internal/ui"
)
func newTestWriter(color bool) (*Writer, *bytes.Buffer) {
func newTestWriter(color bool) (*ui.Writer, *bytes.Buffer) {
buf := &bytes.Buffer{}
return NewWithColor(buf, color), buf
return ui.NewWithColor(buf, color), buf
}
func TestMessageMethodsPlain(t *testing.T) {
t.Parallel()
tests := []struct {
method string
fn func(*Writer)
fn func(*ui.Writer)
want string
}{
{"Begin", func(w *Writer) { w.Beginf("starting %s", "thing") }, "》 starting thing\n"},
{"Complete", func(w *Writer) { w.Completef("done %s", "thing") }, "》 done thing\n"},
{"Info", func(w *Writer) { w.Infof("status") }, "》 status\n"},
{"Notice", func(w *Writer) { w.Noticef("note") }, "》 note\n"},
{"Warning", func(w *Writer) { w.Warningf("oops") }, "⚠️ Warning: oops\n"},
{"Error", func(w *Writer) { w.Errorf("boom") }, "🛑 ERROR: boom\n"},
{"Progress", func(w *Writer) { w.Progressf("p") }, " 》 p\n"},
{"Detail", func(w *Writer) { w.Detailf("d") }, " 》 d\n"},
{"Banner", func(w *Writer) { w.Bannerf("hello") }, "hello\n"}, // plain mode, no bold
{"Begin", func(w *ui.Writer) { w.Beginf("starting %s", "thing") },
"》 starting thing\n"},
{"Complete", func(w *ui.Writer) { w.Completef("done %s", "thing") },
"》 done thing\n"},
{"Info", func(w *ui.Writer) { w.Infof("status") }, "》 status\n"},
{"Notice", func(w *ui.Writer) { w.Noticef("note") }, "》 note\n"},
{"Warning", func(w *ui.Writer) { w.Warningf("oops") }, "⚠️ Warning: oops\n"},
{"Error", func(w *ui.Writer) { w.Errorf("boom") }, "🛑 ERROR: boom\n"},
{"Progress", func(w *ui.Writer) { w.Progressf("p") }, " 》 p\n"},
{"Detail", func(w *ui.Writer) { w.Detailf("d") }, " 》 d\n"},
{"Banner", func(w *ui.Writer) { w.Bannerf("hello") }, "hello\n"}, // plain, no bold
}
for _, tt := range tests {
t.Run(tt.method, func(t *testing.T) {
t.Parallel()
w, buf := newTestWriter(false)
tt.fn(w)
@@ -43,6 +51,8 @@ func TestMessageMethodsPlain(t *testing.T) {
}
func TestWarningErrorCounters(t *testing.T) {
t.Parallel()
w, _ := newTestWriter(false)
if w.WarningCount() != 0 || w.ErrorCount() != 0 {
t.Fatalf("expected fresh writer to have zero counts")
@@ -63,6 +73,8 @@ func TestWarningErrorCounters(t *testing.T) {
}
func TestColorOutputContainsANSI(t *testing.T) {
t.Parallel()
w, buf := newTestWriter(true)
w.Errorf("boom")
@@ -77,6 +89,8 @@ func TestColorOutputContainsANSI(t *testing.T) {
}
func TestBannerBoldWhenColor(t *testing.T) {
t.Parallel()
w, buf := newTestWriter(true)
w.Bannerf("hello")
@@ -87,6 +101,8 @@ func TestBannerBoldWhenColor(t *testing.T) {
}
func TestValueFormattersPlain(t *testing.T) {
t.Parallel()
w, _ := newTestWriter(false)
if got := w.Hex("0123456789abcdef0123"); got != "0123456789ab..." {
@@ -127,18 +143,26 @@ func TestValueFormattersPlain(t *testing.T) {
}
// Time format: today → HH:MM:SS, other day → YYYY-MM-DD HH:MM:SS.
today := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 14, 30, 45, 0, time.Local)
// These construct local-zone times on purpose: Writer.Time displays
// in the process's local zone.
now := time.Now()
today := time.Date(now.Year(), now.Month(), now.Day(),
14, 30, 45, 0, time.Local) //nolint:gosmopolitan // local display
if got := w.Time(today); got != "14:30:45" {
t.Errorf("Time today: got %q, want 14:30:45", got)
}
other := time.Date(2030, 1, 2, 3, 4, 5, 0, time.Local)
other := time.Date(2030, 1, 2, 3, 4, 5, 0,
time.Local) //nolint:gosmopolitan // local display
if got := w.Time(other); got != "2030-01-02 03:04:05" {
t.Errorf("Time other day: got %q", got)
}
}
func TestValueFormattersColored(t *testing.T) {
t.Parallel()
w, _ := newTestWriter(true)
hex := w.Hex("0123456789abcdef0123")