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:
@@ -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,15 +116,6 @@ 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 ─────────────────────────
|
||||
|
||||
// Beginf prints an operation-start line, left-aligned with a white marker.
|
||||
@@ -208,17 +212,6 @@ func (w *Writer) Bannerf(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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user