tenseleyflow/shithub / a73b2e2

Browse files

drop var-_-equals-symbol unused-import shims (SR2 M1)

Pre-fix: 8 sites carried 'var _ = symbol' shims with comments like
'silence unused-import warnings during refactors'. These were lying:
in every case the import was already used elsewhere in the file or
the symbol was unreachable. Audit 2026-05-08 flagged 3 occurrences;
audit 2026-05-10 found 8 — the pattern grew because nothing failed
CI on it.

Sites cleaned:
- internal/auth/totp/recovery.go (base32.StdEncoding)
- internal/web/middleware/pat.go (pgx.ErrNoRows)
- internal/web/handlers/orgs/teams.go (pgx.ErrNoRows + errors.New)
- internal/web/handlers/profile/profile.go (context.Background)
- internal/web/handlers/api/api.go (context.Background)
- internal/web/handlers/repo/code.go (pgtype.Int8{})
- internal/web/handlers/repo/redirect.go (usersdb.New)

Build still passes after each shim drop because the imports are
genuinely live; the shims were cargo-cult.
Authored by espadonne
SHA
a73b2e28962820aa766759ab953b1aaa6cad9451
Parents
c8058f1
Tree
192f834

7 changed files

StatusFile+-
M internal/auth/totp/recovery.go 0 4
M internal/web/handlers/api/api.go 0 4
M internal/web/handlers/orgs/teams.go 0 11
M internal/web/handlers/profile/profile.go 0 5
M internal/web/handlers/repo/code.go 0 5
M internal/web/handlers/repo/redirect.go 0 5
M internal/web/middleware/pat.go 0 5
internal/auth/totp/recovery.gomodified
@@ -6,7 +6,6 @@ import (
66
 	"crypto/rand"
77
 	"crypto/sha256"
88
 	"crypto/subtle"
9
-	"encoding/base32"
109
 	"errors"
1110
 	"strings"
1211
 )
@@ -118,6 +117,3 @@ func mintCode() (string, error) {
118117
 // ErrRecoveryCodeInvalid is returned by callers when the typed code
119118
 // doesn't match any stored hash.
120119
 var ErrRecoveryCodeInvalid = errors.New("totp: recovery code invalid")
121
-
122
-// noOpUseStdEncoding silences unused-import warnings during refactors.
123
-var _ = base32.StdEncoding
internal/web/handlers/api/api.gomodified
@@ -10,7 +10,6 @@
1010
 package api
1111
 
1212
 import (
13
-	"context"
1413
 	"encoding/json"
1514
 	"errors"
1615
 	"net/http"
@@ -120,6 +119,3 @@ func writeJSON(w http.ResponseWriter, status int, body any) {
120119
 func writeAPIError(w http.ResponseWriter, status int, msg string) {
121120
 	writeJSON(w, status, map[string]string{"error": msg})
122121
 }
123
-
124
-// silence unused import on the rare branch where context is not used.
125
-var _ = context.Background
internal/web/handlers/orgs/teams.gomodified
@@ -3,13 +3,11 @@
33
 package orgs
44
 
55
 import (
6
-	"errors"
76
 	"net/http"
87
 	"strconv"
98
 	"strings"
109
 
1110
 	"github.com/go-chi/chi/v5"
12
-	"github.com/jackc/pgx/v5"
1311
 
1412
 	"github.com/tenseleyFlow/shithub/internal/orgs"
1513
 	orgsdb "github.com/tenseleyFlow/shithub/internal/orgs/sqlc"
@@ -307,12 +305,3 @@ func (h *Handlers) filterSecretTeams(r *http.Request, all []orgsdb.Team, orgID i
307305
 func (h *Handlers) teamPath(org orgsdb.Org, team orgsdb.Team) string {
308306
 	return "/" + string(org.Slug) + "/teams/" + string(team.Slug)
309307
 }
310
-
311
-// ensure pgx is referenced when the rest of the file's imports
312
-// settle (avoids a "imported and not used" if a future refactor
313
-// drops the only inline pgx use).
314
-var _ = pgx.ErrNoRows
315
-
316
-// errTeamNotFound is reserved for the future; surfaced via
317
-// orgs.ErrTeamNotFound when needed.
318
-var _ = errors.New
internal/web/handlers/profile/profile.gomodified
@@ -11,7 +11,6 @@
1111
 package profile
1212
 
1313
 import (
14
-	"context"
1514
 	"errors"
1615
 	"fmt"
1716
 	"html/template"
@@ -297,7 +296,3 @@ func safeWebsite(s string) template.URL {
297296
 	}
298297
 	return template.URL(u.String()) //nolint:gosec // schemes vetted above.
299298
 }
300
-
301
-// ensure context import is used by static analysis even if a future
302
-// refactor removes its only inline use.
303
-var _ = context.Background
internal/web/handlers/repo/code.gomodified
@@ -12,7 +12,6 @@ import (
1212
 	"strings"
1313
 
1414
 	"github.com/go-chi/chi/v5"
15
-	"github.com/jackc/pgx/v5/pgtype"
1615
 
1716
 	"github.com/tenseleyFlow/shithub/internal/auth/policy"
1817
 	mdrender "github.com/tenseleyFlow/shithub/internal/markdown"
@@ -503,7 +502,3 @@ func joinPath(parent, child string) string {
503502
 	}
504503
 	return parent + "/" + child
505504
 }
506
-
507
-// silence pgtype unused-import warning when the loadRepoAndAuthorize
508
-// helper is in this file's package but defined elsewhere.
509
-var _ = pgtype.Int8{}
internal/web/handlers/repo/redirect.gomodified
@@ -9,7 +9,6 @@ import (
99
 	"github.com/jackc/pgx/v5/pgtype"
1010
 
1111
 	reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc"
12
-	usersdb "github.com/tenseleyFlow/shithub/internal/users/sqlc"
1312
 )
1413
 
1514
 // tryRedirect resolves a (stale_owner, stale_name) URL to its current
@@ -50,7 +49,3 @@ func (h *Handlers) tryRedirect(r *http.Request, ownerName, repoName string) stri
5049
 	tail := strings.TrimPrefix(r.URL.Path, "/"+ownerName+"/"+repoName)
5150
 	return "/" + currentOwner + "/" + row.Name + tail
5251
 }
53
-
54
-// _ keeps usersdb imported even when only its types are referenced
55
-// indirectly via the handlers struct. Unused-import guard.
56
-var _ = usersdb.New
internal/web/middleware/pat.gomodified
@@ -12,7 +12,6 @@ import (
1212
 	"strings"
1313
 	"time"
1414
 
15
-	"github.com/jackc/pgx/v5"
1615
 	"github.com/jackc/pgx/v5/pgxpool"
1716
 
1817
 	"github.com/tenseleyFlow/shithub/internal/auth/pat"
@@ -235,7 +234,3 @@ func remoteAddrFromRequest(r *http.Request) *netip.Addr {
235234
 	}
236235
 	return nil
237236
 }
238
-
239
-// ensure pgx import is used by static-analysis tools (the ErrNoRows
240
-// sentinel is referenced via err comparison in dependent middleware).
241
-var _ = pgx.ErrNoRows