From d58e3e2653a95da7cfb16ab435502743138954e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Untersch=C3=BCtz?= Date: Mon, 23 Nov 2026 07:12:20 +0100 Subject: [PATCH] chore(lint): re-enable staticcheck and unused golangci-lint v2.15.0 ships a honnef.co/go/tools that analyzes the Go 1.27 standard library without panicking. Fix what they found: dead helpers, an unused constant, error strings starting with a product name, the usage error, and two negations simplified by De Morgan. Closes #43 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3 --- .gitea/workflows/ci.yaml | 2 +- .golangci.yml | 4 ++-- cmd/api/admin.go | 9 +++++++-- cmd/api/main.go | 2 +- cmd/checker/main.go | 2 +- cmd/statuspage/main.go | 2 +- internal/api/audit.go | 2 +- internal/api/groups.go | 3 --- internal/notify/email.go | 2 +- internal/notify/incident.go | 2 +- internal/notify/sms.go | 2 +- internal/pdf/pdf.go | 5 ++--- internal/sso/sso.go | 2 +- internal/statuspage/statuspage_test.go | 6 ------ 14 files changed, 20 insertions(+), 25 deletions(-) diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 5bdddfd..e484792 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -11,7 +11,7 @@ concurrency: cancel-in-progress: true env: - GOLANGCI_LINT_VERSION: v2.12.2 + GOLANGCI_LINT_VERSION: v2.15.0 SQLC_VERSION: v1.31.1 jobs: diff --git a/.golangci.yml b/.golangci.yml index f9af16d..dc0c0d9 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,8 +4,6 @@ run: tests: true linters: - # staticcheck and unused are left out until honnef.co/go/tools supports - # the Go 1.27 standard library; they panic during analysis otherwise. default: none enable: - errcheck @@ -17,6 +15,8 @@ linters: - misspell - unconvert - usestdlibvars + - staticcheck + - unused settings: revive: rules: diff --git a/cmd/api/admin.go b/cmd/api/admin.go index 6b5e793..1defaff 100644 --- a/cmd/api/admin.go +++ b/cmd/api/admin.go @@ -30,6 +30,11 @@ const usage = `usage: region and agent manage platform resources shared by all organizations; organizations manage their own in the console.` +// usageError reports a command line the binary does not understand. +type usageError struct{} + +func (usageError) Error() string { return usage } + // admin runs operator commands. They act across all organizations, hence the // system scope, and print to stdout for humans and scripts. func admin(ctx context.Context, cfg config.API, args []string) error { @@ -96,7 +101,7 @@ func admin(ctx context.Context, cfg config.API, args []string) error { return err }) } - return errors.New(usage) + return usageError{} } func createAgent(ctx context.Context, db *tenant.DB, args []string) error { @@ -108,7 +113,7 @@ func createAgent(ctx context.Context, db *tenant.DB, args []string) error { return err } if *name == "" || (*kind == "checker") != (*region != "") { - return errors.New(usage) + return usageError{} } var tok string err := db.Tx(ctx, tenant.System(), func(q *store.Queries) error { diff --git a/cmd/api/main.go b/cmd/api/main.go index f06760f..6ed3189 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -50,7 +50,7 @@ func run(log *slog.Logger, level *slog.LevelVar, args []string) error { return admin(ctx, cfg, args) case "serve": default: - return errors.New(usage) + return usageError{} } } diff --git a/cmd/checker/main.go b/cmd/checker/main.go index 7c6959b..cc64489 100644 --- a/cmd/checker/main.go +++ b/cmd/checker/main.go @@ -35,7 +35,7 @@ func run(log *slog.Logger, level *slog.LevelVar) error { return err } level.Set(cfg.LogLevel) - if err := cfg.Common.Validate(); err != nil { + if err := cfg.Validate(); err != nil { return err } ctx, stop := platform.SignalContext() diff --git a/cmd/statuspage/main.go b/cmd/statuspage/main.go index b650ed0..f44fb12 100644 --- a/cmd/statuspage/main.go +++ b/cmd/statuspage/main.go @@ -43,7 +43,7 @@ func run(log *slog.Logger, level *slog.LevelVar) error { return err } level.Set(cfg.LogLevel) - if err := cfg.Common.Validate(); err != nil { + if err := cfg.Validate(); err != nil { return err } ctx, stop := platform.SignalContext() diff --git a/internal/api/audit.go b/internal/api/audit.go index 4e0549a..f57c85b 100644 --- a/internal/api/audit.go +++ b/internal/api/audit.go @@ -177,7 +177,7 @@ func (s *Server) audit() gin.HandlerFunc { action := auditActions[c.Request.Method+" "+c.FullPath()] status := c.Writer.Status() - if action == "" || c.GetBool(ctxAuditSkip) || (status >= 400 && !(auditFailures[action] && status < 500)) { + if action == "" || c.GetBool(ctxAuditSkip) || (status >= 400 && (!auditFailures[action] || status >= 500)) { return } if status >= 400 { diff --git a/internal/api/groups.go b/internal/api/groups.go index 0a344bc..d4f8e80 100644 --- a/internal/api/groups.go +++ b/internal/api/groups.go @@ -68,9 +68,6 @@ func (t groupTree) resources(group *uuid.UUID) []authz.Resource { return out } -// depth returns how many ancestors a group has. -func (t groupTree) depth(id uuid.UUID) int { return len(t.resources(&id)) - 1 } - // walk visits groups depth-first in name order. func (t groupTree) walk(fn func(g store.MonitorGroup, depth int)) { var visit func(ids []uuid.UUID, depth int) diff --git a/internal/notify/email.go b/internal/notify/email.go index eb3c321..a2fa6ec 100644 --- a/internal/notify/email.go +++ b/internal/notify/email.go @@ -114,7 +114,7 @@ var emailProviders = []Provider{ AccessToken string `json:"access_token"` } if json.Unmarshal(reply, &tok) != nil || tok.AccessToken == "" { - return errors.New("Microsoft Entra issued no access token") + return errors.New("no access token from Microsoft Entra") } recipients := func(s string) []any { return addresses(s, func(a string) any { return map[string]any{"emailAddress": map[string]string{"address": a}} }) diff --git a/internal/notify/incident.go b/internal/notify/incident.go index a58efc4..3b9dacc 100644 --- a/internal/notify/incident.go +++ b/internal/notify/incident.go @@ -124,7 +124,7 @@ var incidentProviders = []Provider{ ID string `json:"id"` } if json.Unmarshal(reply, &alert) != nil || alert.ID == "" { - return errors.New("Jira Service Management: alert to close not found") + return errors.New("alert to close not found in Jira Service Management") } return c.json(ctx, http.MethodPost, base+"/"+url.PathEscape(alert.ID)+"/close", h, map[string]any{"source": "UptimeSebi"}) } diff --git a/internal/notify/sms.go b/internal/notify/sms.go index 032b31b..cba98c0 100644 --- a/internal/notify/sms.go +++ b/internal/notify/sms.go @@ -356,7 +356,7 @@ var smsProviders = []Provider{ } `json:"data"` } if err != nil || json.Unmarshal(reply, &login) != nil || !login.Success { - return errors.Join(errors.New("Teltonika: sign-in failed"), err) + return errors.Join(errors.New("sign-in to Teltonika failed"), err) } reply, err = c.callJSON(ctx, http.MethodPost, base+"/api/messages/actions/send", bearer(login.Data.Token), map[string]any{ "data": map[string]any{"modem": cfg["modem"], "number": cfg["phone_number"], "message": truncate(m.sms(), 159)}, diff --git a/internal/pdf/pdf.go b/internal/pdf/pdf.go index 6644e2b..1ef5c77 100644 --- a/internal/pdf/pdf.go +++ b/internal/pdf/pdf.go @@ -21,11 +21,10 @@ const ( margin = 50.0 bodySize = 9.0 lineHeight = 12.0 - // Courier advances 0.6 em per character, which makes wrapping exact. - charWidth = 0.6 * bodySize ) -// maxChars is how many Courier characters fit on a line. +// maxChars is how many Courier characters fit on a line: Courier advances +// 0.6 em per character, which makes wrapping exact. const maxChars = 91 type font string diff --git a/internal/sso/sso.go b/internal/sso/sso.go index c46bb03..8e8c0e5 100644 --- a/internal/sso/sso.go +++ b/internal/sso/sso.go @@ -96,7 +96,7 @@ func (c *Client) checkIssuer(issuer string) error { if err != nil || u.Host == "" || u.RawQuery != "" || u.Fragment != "" || u.User != nil { return ErrInvalidIssuer } - if u.Scheme != "https" && !(c.allowHTTP && u.Scheme == "http") { + if u.Scheme != "https" && (!c.allowHTTP || u.Scheme != "http") { return ErrInvalidIssuer } return nil diff --git a/internal/statuspage/statuspage_test.go b/internal/statuspage/statuspage_test.go index 1781796..20ce9c2 100644 --- a/internal/statuspage/statuspage_test.go +++ b/internal/statuspage/statuspage_test.go @@ -55,12 +55,6 @@ func (f *fakeSource) set(fn func(*fakeSource)) { fn(f) } -func (f *fakeSource) callCount() int { - f.mu.Lock() - defer f.mu.Unlock() - return f.calls -} - type harness struct { srv *Server src *fakeSource -- 2.54.1