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 (
6
 	"crypto/rand"
6
 	"crypto/rand"
7
 	"crypto/sha256"
7
 	"crypto/sha256"
8
 	"crypto/subtle"
8
 	"crypto/subtle"
9
-	"encoding/base32"
10
 	"errors"
9
 	"errors"
11
 	"strings"
10
 	"strings"
12
 )
11
 )
@@ -118,6 +117,3 @@ func mintCode() (string, error) {
118
 // ErrRecoveryCodeInvalid is returned by callers when the typed code
117
 // ErrRecoveryCodeInvalid is returned by callers when the typed code
119
 // doesn't match any stored hash.
118
 // doesn't match any stored hash.
120
 var ErrRecoveryCodeInvalid = errors.New("totp: recovery code invalid")
119
 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 @@
10
 package api
10
 package api
11
 
11
 
12
 import (
12
 import (
13
-	"context"
14
 	"encoding/json"
13
 	"encoding/json"
15
 	"errors"
14
 	"errors"
16
 	"net/http"
15
 	"net/http"
@@ -120,6 +119,3 @@ func writeJSON(w http.ResponseWriter, status int, body any) {
120
 func writeAPIError(w http.ResponseWriter, status int, msg string) {
119
 func writeAPIError(w http.ResponseWriter, status int, msg string) {
121
 	writeJSON(w, status, map[string]string{"error": msg})
120
 	writeJSON(w, status, map[string]string{"error": msg})
122
 }
121
 }
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 @@
3
 package orgs
3
 package orgs
4
 
4
 
5
 import (
5
 import (
6
-	"errors"
7
 	"net/http"
6
 	"net/http"
8
 	"strconv"
7
 	"strconv"
9
 	"strings"
8
 	"strings"
10
 
9
 
11
 	"github.com/go-chi/chi/v5"
10
 	"github.com/go-chi/chi/v5"
12
-	"github.com/jackc/pgx/v5"
13
 
11
 
14
 	"github.com/tenseleyFlow/shithub/internal/orgs"
12
 	"github.com/tenseleyFlow/shithub/internal/orgs"
15
 	orgsdb "github.com/tenseleyFlow/shithub/internal/orgs/sqlc"
13
 	orgsdb "github.com/tenseleyFlow/shithub/internal/orgs/sqlc"
@@ -307,12 +305,3 @@ func (h *Handlers) filterSecretTeams(r *http.Request, all []orgsdb.Team, orgID i
307
 func (h *Handlers) teamPath(org orgsdb.Org, team orgsdb.Team) string {
305
 func (h *Handlers) teamPath(org orgsdb.Org, team orgsdb.Team) string {
308
 	return "/" + string(org.Slug) + "/teams/" + string(team.Slug)
306
 	return "/" + string(org.Slug) + "/teams/" + string(team.Slug)
309
 }
307
 }
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 @@
11
 package profile
11
 package profile
12
 
12
 
13
 import (
13
 import (
14
-	"context"
15
 	"errors"
14
 	"errors"
16
 	"fmt"
15
 	"fmt"
17
 	"html/template"
16
 	"html/template"
@@ -297,7 +296,3 @@ func safeWebsite(s string) template.URL {
297
 	}
296
 	}
298
 	return template.URL(u.String()) //nolint:gosec // schemes vetted above.
297
 	return template.URL(u.String()) //nolint:gosec // schemes vetted above.
299
 }
298
 }
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 (
12
 	"strings"
12
 	"strings"
13
 
13
 
14
 	"github.com/go-chi/chi/v5"
14
 	"github.com/go-chi/chi/v5"
15
-	"github.com/jackc/pgx/v5/pgtype"
16
 
15
 
17
 	"github.com/tenseleyFlow/shithub/internal/auth/policy"
16
 	"github.com/tenseleyFlow/shithub/internal/auth/policy"
18
 	mdrender "github.com/tenseleyFlow/shithub/internal/markdown"
17
 	mdrender "github.com/tenseleyFlow/shithub/internal/markdown"
@@ -503,7 +502,3 @@ func joinPath(parent, child string) string {
503
 	}
502
 	}
504
 	return parent + "/" + child
503
 	return parent + "/" + child
505
 }
504
 }
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 (
9
 	"github.com/jackc/pgx/v5/pgtype"
9
 	"github.com/jackc/pgx/v5/pgtype"
10
 
10
 
11
 	reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc"
11
 	reposdb "github.com/tenseleyFlow/shithub/internal/repos/sqlc"
12
-	usersdb "github.com/tenseleyFlow/shithub/internal/users/sqlc"
13
 )
12
 )
14
 
13
 
15
 // tryRedirect resolves a (stale_owner, stale_name) URL to its current
14
 // 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
50
 	tail := strings.TrimPrefix(r.URL.Path, "/"+ownerName+"/"+repoName)
49
 	tail := strings.TrimPrefix(r.URL.Path, "/"+ownerName+"/"+repoName)
51
 	return "/" + currentOwner + "/" + row.Name + tail
50
 	return "/" + currentOwner + "/" + row.Name + tail
52
 }
51
 }
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 (
12
 	"strings"
12
 	"strings"
13
 	"time"
13
 	"time"
14
 
14
 
15
-	"github.com/jackc/pgx/v5"
16
 	"github.com/jackc/pgx/v5/pgxpool"
15
 	"github.com/jackc/pgx/v5/pgxpool"
17
 
16
 
18
 	"github.com/tenseleyFlow/shithub/internal/auth/pat"
17
 	"github.com/tenseleyFlow/shithub/internal/auth/pat"
@@ -235,7 +234,3 @@ func remoteAddrFromRequest(r *http.Request) *netip.Addr {
235
 	}
234
 	}
236
 	return nil
235
 	return nil
237
 }
236
 }
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