Update golangci-lint to v2.12.2 with canonical config (#62)
All checks were successful
check / check (push) Successful in 5s

Updates golangci-lint to v2.12.2 everywhere it is pinned and installs the canonical `.golangci.yml`, then remediates every finding the new linter/config surfaces so `make check` is green.

## Version bump

- `Dockerfile` lint stage: `golangci/golangci-lint:v2.11.3-alpine` -> `v2.12.2-alpine` (digest-pinned, date comment updated)
- `Makefile` `deps` target: `go install` moved from the old v1 module path at `@latest` to the pinned `github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2`
- `.golangci.yml` replaced with the canonical config (v2 schema; settings under `linters.settings` so the thresholds actually apply; `default: all` with the standard six disables)
- `script/bootstrap` installs golangci-lint via the system package manager and carries no version pin, so it is unchanged
- CI (`.gitea/workflows/check.yml`) only runs `script/cibuild`, so it needed no change

## Lint remediation

The canonical config surfaced ~3,300 findings across 56k lines. All are fixed, behavior-preserving; incorporates and supersedes the per-package mechanical passes already merged to `main` (refs #61). Highlights:

- `err113`: dynamic errors replaced with package sentinels + `%w` wrapping; comparisons via `errors.Is`
- `goprintffuncname`: printf-style helpers renamed with an `f` suffix (`ui.Writer` message methods, `cli.ReportErrorf`, `database.Fatalf`) and all call sites updated
- `revive` stutter renames: `blob.Handler`, `blob.WithReader`, `blob.ChunkPosition`, `storage.URL`, `storage.Info`; missing doc comments added
- `contextcheck`/`noctx`: `context.Context` threaded through `blob.Packer` and the scanner call sites; context-aware `exec`/`sql` variants
- `funlen`/`cyclop`/`gocognit`/`dupl`: oversized and duplicated functions split into focused helpers (production and test code)
- tests: `t.Parallel()` added where safe (global logger init kept in the serial phase for `-race`), `t.TempDir()`/`t.Helper()` adopted, several suites converted to external test packages
- `gosec`: bounded integer conversions, `ReadHeaderTimeout` on the test HTTP server; remaining warnings suppressed per-site with justifications
- remaining `nolint` directives are rare, targeted, and each carries a reason (e.g. `nilnil` not-found contract in the repository layer, fx module globals, on-disk snake_case struct tags)
- removed the deprecated `log.LogOptions` alias (callers migrated to `log.Options`)

`make check` (tests with `-race`, lint, fmt-check) passes.

Co-authored-by: sneak <sneak@sneak.berlin>
Reviewed-on: #62
Co-authored-by: clawbot <clawbot@noreply.example.org>
Co-committed-by: clawbot <clawbot@noreply.example.org>
This commit was merged in pull request #62.
This commit is contained in:
2026-08-07 23:22:48 +02:00
committed by Jeffrey Paul
parent b87b72d4b9
commit cc58583130
126 changed files with 8184 additions and 5470 deletions

View File

@@ -4,14 +4,14 @@
//
// Message classes (see Writer methods):
//
// - Begin — operation start, left-aligned, marker "》" (white)
// - Complete— operation completion, left-aligned, marker "》" (green)
// - Info — left-aligned neutral status, marker "》" (white)
// - Notice — left-aligned important note, marker "》" (cyan)
// - Warning — left-aligned warning, full word "Warning: " (orange/yellow)
// - Error — left-aligned error, full word "ERROR: " (red)
// - Progress— indented heartbeat / per-item update, marker " 》" (white)
// - Banner — application banner line, left-aligned, no marker
// - Beginf — operation start, left-aligned, marker "》" (white)
// - Completef— operation completion, left-aligned, marker "》" (green)
// - Infof — left-aligned neutral status, marker "》" (white)
// - Noticef — left-aligned important note, marker "》" (cyan)
// - Warningf — left-aligned warning, full word "Warning: " (orange/yellow)
// - Errorf — left-aligned error, full word "ERROR: " (red)
// - Progressf— indented heartbeat / per-item update, marker " 》" (white)
// - Bannerf — application banner line, left-aligned, no marker
//
// Value formatters (Hex, Size, Duration, Time, Path, Snapshot, Speed,
// Count, Percent) return ANSI-colored strings the caller composes into
@@ -45,6 +45,19 @@ const (
// Marker is the chevron prefix used for all non-error/warning lines.
const Marker = "》"
const (
// hexAbbrevLen is the number of hash characters Hex keeps before "...".
hexAbbrevLen = 12
// bitsPerByte converts bytes/sec into bits/sec for Speed.
bitsPerByte = 8
// SI thresholds for Speed's unit selection, in bits/sec.
gigabit = 1e9
megabit = 1e6
kilobit = 1e3
)
// Writer formats and emits user-facing messages with optional ANSI color.
// It also counts warnings and errors emitted so the caller can summarize at
// the end of an operation ("Finished successfully." vs "Finished with
@@ -103,19 +116,10 @@ func shouldColor(w io.Writer) bool {
return term.IsTerminal(int(f.Fd()))
}
// paint wraps s in the given ANSI color when color is enabled.
func (w *Writer) paint(color, s string) string {
if !w.color {
return s
}
return color + s + ansiReset
}
// ───────────────────────── message methods ─────────────────────────
// Begin prints an operation-start line, left-aligned with a white marker.
func (w *Writer) Begin(format string, args ...any) {
// Beginf prints an operation-start line, left-aligned with a white marker.
func (w *Writer) Beginf(format string, args ...any) {
if w.quiet {
return
}
@@ -123,8 +127,8 @@ func (w *Writer) Begin(format string, args ...any) {
w.emit(ansiWhite, Marker, "", format, args)
}
// Complete prints an operation-completion line in green, left-aligned.
func (w *Writer) Complete(format string, args ...any) {
// Completef prints an operation-completion line in green, left-aligned.
func (w *Writer) Completef(format string, args ...any) {
if w.quiet {
return
}
@@ -132,8 +136,8 @@ func (w *Writer) Complete(format string, args ...any) {
w.emit(ansiGreen, Marker, ansiGreen, format, args)
}
// Info prints a neutral status line, left-aligned with a white marker.
func (w *Writer) Info(format string, args ...any) {
// Infof prints a neutral status line, left-aligned with a white marker.
func (w *Writer) Infof(format string, args ...any) {
if w.quiet {
return
}
@@ -141,8 +145,8 @@ func (w *Writer) Info(format string, args ...any) {
w.emit(ansiWhite, Marker, "", format, args)
}
// Notice prints an attention-worthy informational line, marker in cyan.
func (w *Writer) Notice(format string, args ...any) {
// Noticef prints an attention-worthy informational line, marker in cyan.
func (w *Writer) Noticef(format string, args ...any) {
if w.quiet {
return
}
@@ -150,27 +154,27 @@ func (w *Writer) Notice(format string, args ...any) {
w.emit(ansiCyan, Marker, "", format, args)
}
// Warning prints "⚠️ Warning: " in orange/yellow followed by the message.
func (w *Writer) Warning(format string, args ...any) {
// Warningf prints "⚠️ Warning: " in orange/yellow followed by the message.
func (w *Writer) Warningf(format string, args ...any) {
w.warnings++
prefix := "⚠️ " + w.paint(ansiYellow+ansiBold, "Warning: ")
_, _ = fmt.Fprintln(w.out, prefix+fmt.Sprintf(format, args...))
}
// Error prints "🛑 ERROR: " in red followed by the message. Goes to the
// Errorf prints "🛑 ERROR: " in red followed by the message. Goes to the
// same writer as everything else; callers that want stderr should
// construct a separate Writer for it.
func (w *Writer) Error(format string, args ...any) {
func (w *Writer) Errorf(format string, args ...any) {
w.errors++
prefix := "🛑 " + w.paint(ansiRed+ansiBold, "ERROR: ")
_, _ = fmt.Fprintln(w.out, prefix+fmt.Sprintf(format, args...))
}
// Detail prints an indented continuation line under a preceding Complete
// Detailf prints an indented continuation line under a preceding Completef
// (or other top-level message). Marker " 》" (white) at column 2.
// Distinct from Progress (semantically a "heartbeat") in usage but
// Distinct from Progressf (semantically a "heartbeat") in usage but
// visually identical.
func (w *Writer) Detail(format string, args ...any) {
func (w *Writer) Detailf(format string, args ...any) {
if w.quiet {
return
}
@@ -184,8 +188,8 @@ func (w *Writer) WarningCount() int { return w.warnings }
// ErrorCount returns the number of Error() calls this writer has emitted.
func (w *Writer) ErrorCount() int { return w.errors }
// Progress prints an indented heartbeat / per-item update, marker in white.
func (w *Writer) Progress(format string, args ...any) {
// Progressf prints an indented heartbeat / per-item update, marker in white.
func (w *Writer) Progressf(format string, args ...any) {
if w.quiet {
return
}
@@ -193,9 +197,9 @@ func (w *Writer) Progress(format string, args ...any) {
w.emit(ansiWhite, " "+Marker, "", format, args)
}
// Banner prints a line with no marker, left-aligned. Bold when color
// Bannerf prints a line with no marker, left-aligned. Bold when color
// is enabled. Used for the application startup banner only.
func (w *Writer) Banner(format string, args ...any) {
func (w *Writer) Bannerf(format string, args ...any) {
if w.quiet {
return
}
@@ -208,17 +212,6 @@ func (w *Writer) Banner(format string, args ...any) {
_, _ = fmt.Fprintln(w.out, body)
}
// emit writes "<prefix> <body>\n" with the prefix painted in prefixColor
// and the body optionally painted in bodyColor (empty = no body color).
func (w *Writer) emit(prefixColor, prefix, bodyColor, format string, args []any) {
body := fmt.Sprintf(format, args...)
if bodyColor != "" {
body = w.paint(bodyColor, body)
}
_, _ = fmt.Fprintln(w.out, w.paint(prefixColor, prefix)+" "+body)
}
// ───────────────────────── value formatters ─────────────────────────
//
// These return ANSI-colored strings the caller composes into a message
@@ -228,8 +221,8 @@ func (w *Writer) emit(prefixColor, prefix, bodyColor, format string, args []any)
// Long hashes are abbreviated to first 12 chars with "...".
func (w *Writer) Hex(s string) string {
short := s
if len(s) > 12 {
short = s[:12] + "..."
if len(s) > hexAbbrevLen {
short = s[:hexAbbrevLen] + "..."
}
return w.paint(ansiCyan, short)
@@ -247,7 +240,7 @@ func (w *Writer) Path(p string) string {
// Size colorizes a byte count using humanize.Bytes.
func (w *Writer) Size(bytes int64) string {
return w.paint(ansiMagenta, humanize.Bytes(uint64(bytes)))
return w.paint(ansiMagenta, humanize.Bytes(uint64(bytes))) //nolint:gosec // G115: >=0
}
// Speed colorizes a network transfer rate. Input is bytes/sec; output is
@@ -258,17 +251,17 @@ func (w *Writer) Speed(bytesPerSec float64) string {
return w.paint(ansiMagenta, "N/A")
}
bitsPerSec := bytesPerSec * 8
bitsPerSec := bytesPerSec * bitsPerByte
var s string
switch {
case bitsPerSec >= 1e9:
s = fmt.Sprintf("%.1f Gbit/sec", bitsPerSec/1e9)
case bitsPerSec >= 1e6:
s = fmt.Sprintf("%.0f Mbit/sec", bitsPerSec/1e6)
case bitsPerSec >= 1e3:
s = fmt.Sprintf("%.0f Kbit/sec", bitsPerSec/1e3)
case bitsPerSec >= gigabit:
s = fmt.Sprintf("%.1f Gbit/sec", bitsPerSec/gigabit)
case bitsPerSec >= megabit:
s = fmt.Sprintf("%.0f Mbit/sec", bitsPerSec/megabit)
case bitsPerSec >= kilobit:
s = fmt.Sprintf("%.0f Kbit/sec", bitsPerSec/kilobit)
default:
s = fmt.Sprintf("%.0f bit/sec", bitsPerSec)
}
@@ -286,7 +279,7 @@ func (w *Writer) Duration(d time.Duration) string {
// "YYYY-MM-DD HH:MM:SS". No timezone is included — values are
// displayed in the process's local zone.
func (w *Writer) Time(t time.Time) string {
t = t.Local()
t = t.Local() //nolint:gosmopolitan // local-time display is intentional
now := time.Now()
if t.Year() == now.Year() && t.YearDay() == now.YearDay() {
@@ -305,3 +298,25 @@ func (w *Writer) Count(n int) string {
func (w *Writer) Percent(p float64) string {
return w.paint(ansiMagenta, fmt.Sprintf("%.1f%%", p))
}
// ───────────────────────── internal helpers ─────────────────────────
// paint wraps s in the given ANSI color when color is enabled.
func (w *Writer) paint(color, s string) string {
if !w.color {
return s
}
return color + s + ansiReset
}
// emit writes "<prefix> <body>\n" with the prefix painted in prefixColor
// and the body optionally painted in bodyColor (empty = no body color).
func (w *Writer) emit(prefixColor, prefix, bodyColor, format string, args []any) {
body := fmt.Sprintf(format, args...)
if bodyColor != "" {
body = w.paint(bodyColor, body)
}
_, _ = fmt.Fprintln(w.out, w.paint(prefixColor, prefix)+" "+body)
}

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.Begin("starting %s", "thing") }, "》 starting thing\n"},
{"Complete", func(w *Writer) { w.Complete("done %s", "thing") }, "》 done thing\n"},
{"Info", func(w *Writer) { w.Info("status") }, "》 status\n"},
{"Notice", func(w *Writer) { w.Notice("note") }, "》 note\n"},
{"Warning", func(w *Writer) { w.Warning("oops") }, "⚠️ Warning: oops\n"},
{"Error", func(w *Writer) { w.Error("boom") }, "🛑 ERROR: boom\n"},
{"Progress", func(w *Writer) { w.Progress("p") }, " 》 p\n"},
{"Detail", func(w *Writer) { w.Detail("d") }, " 》 d\n"},
{"Banner", func(w *Writer) { w.Banner("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,15 +51,17 @@ 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")
}
w.Info("normal")
w.Warning("first warn")
w.Warning("second warn")
w.Error("only error")
w.Infof("normal")
w.Warningf("first warn")
w.Warningf("second warn")
w.Errorf("only error")
if got, want := w.WarningCount(), 2; got != want {
t.Errorf("WarningCount: got %d, want %d", got, want)
@@ -63,8 +73,10 @@ func TestWarningErrorCounters(t *testing.T) {
}
func TestColorOutputContainsANSI(t *testing.T) {
t.Parallel()
w, buf := newTestWriter(true)
w.Error("boom")
w.Errorf("boom")
out := buf.String()
if !strings.Contains(out, "\033[") {
@@ -77,8 +89,10 @@ func TestColorOutputContainsANSI(t *testing.T) {
}
func TestBannerBoldWhenColor(t *testing.T) {
t.Parallel()
w, buf := newTestWriter(true)
w.Banner("hello")
w.Bannerf("hello")
out := buf.String()
if !strings.Contains(out, "\033[1m") {
@@ -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")