Update golangci-lint to v2.12.2 with canonical config (#62)
All checks were successful
check / check (push) Successful in 5s
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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user