Skip to content

Commit fa7440a

Browse files
atulmguptaCopilot
andcommitted
lint: delete pre-existing dead helpers instead of suppressing them
Per review feedback: //nolint:unused directives on 28 pre-existing helpers (funcs, methods, vars, types, consts, struct field) were masking dead code rather than fixing it. Removed each helper after verifying zero callers within its declaring package (the unused linter is package-scoped and these are all unexported, so cross-package callers are impossible by construction). Deleted symbols (20 files / 403 lines net removed): internal/ai/rag/pgvector.go isProviderGateClosed internal/api/automation_handler_test_run checkWebhookTokenUniqueness, errWebhookTokenDuplicate, duplicateTokenError, (*duplicateTokenError).Error internal/api/battery_cells_handler.go frontendCell type internal/api/battery_handler.go nominalRangeKm const internal/api/chatbot_handler.go (*ChatbotHandler).queryVehicleLocation internal/api/export_handler.go ptrFloatMpsToMphAPI, ptrInt16 internal/api/middleware.go tracedTransport internal/api/polling_handler.go writeJSONPolling internal/api/share_handler.go (*ShareHandler).buildFromTelemetry internal/api/telemetry_handler.go toBool, parseBuckleStatus, toTimestamp, (*TelemetryHandler).trackVehicleConfig, formatSignalName (+ var _ trick); also stale Phase-42 comments referencing deleted trackSecurity/trackUserPreferences internal/api/telemetry_sessions_signal_helpers.go derefInt16AsInt internal/api/vehicle_settings_handler.go drainBody internal/api/watch_handler.go derefInt internal/automation/engine.go Engine.mu field internal/database/settings_serializer.go ptrInt64Eq internal/database/sudo_token_repo.go (*SudoTokenStore).withClock internal/database/tesla_energy_history_repo.go validJSON (+ orphan Helpers section header) internal/export/processor.go ptrInt, ptrInt16 internal/fsm/machine.go (*VehicleFSM).buildSignalContext internal/fsm/transition.go guardNames Also pruned the now-unused imports surfaced by the deletions: pgvector.go drops 'errors'; engine.go drops 'sync'; chatbot_handler.go drops 'strings'; polling_handler.go drops 'encoding/json'; telemetry_handler.go drops 'strconv', 'strings', 'github.com/rs/zerolog/log'; vehicle_settings_handler.go drops 'io'; tesla_energy_history_repo.go drops 'encoding/json'. Verification (matches the CI matrix): go build ./... ✓ go vet ./... ✓ golangci-lint run ./... ✓ (0 issues) go test ./... ✓ all 157 packages archmetrics -compare baseline.json ✓ npx tsc --noEmit ✓ (frontend untouched) Net effect: zero behavioural change, 28 //nolint:unused suppressions gone, no //nolint:unused // pre-existing directives remain anywhere in the tree. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 87bd0a5 commit fa7440a

20 files changed

Lines changed: 0 additions & 403 deletions

internal/ai/rag/pgvector.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"crypto/sha256"
66
"encoding/hex"
7-
"errors"
87
"fmt"
98
"time"
109

@@ -469,11 +468,3 @@ func (s *staticResolver) For(_ context.Context, _ string) (provider.Provider, er
469468
return s.p, nil
470469
}
471470

472-
// Helper: detect whether an error means "the resolver gate flipped
473-
// between calls" so a Retrieve loop can degrade silently rather than
474-
// spam the audit log.
475-
//nolint:unused // pre-existing func retained pending follow-up cleanup
476-
func isProviderGateClosed(err error) bool {
477-
return errors.Is(err, provider.ErrProviderDisabled) ||
478-
errors.Is(err, provider.ErrFeatureDisabled)
479-
}

internal/api/automation_handler_test_run.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,6 @@ import (
1515
"github.com/ev-dev-labs/teslasync/internal/models"
1616
)
1717

18-
// checkWebhookTokenUniqueness verifies that no other automation uses the same
19-
// webhook_token. excludeID is the ID to skip (for updates); pass 0 for creates.
20-
//nolint:unused // pre-existing func retained pending follow-up cleanup
21-
func (h *AutomationHandler) checkWebhookTokenUniqueness(r *http.Request, config json.RawMessage, excludeID int64) error {
22-
var cfg struct {
23-
WebhookToken string `json:"webhook_token"`
24-
}
25-
if err := json.Unmarshal(config, &cfg); err != nil || cfg.WebhookToken == "" {
26-
return nil // webhook token extraction not possible — skip check
27-
}
28-
29-
existing, err := (*models.Automation)(nil), error(nil) // webhook token lookup removed in post-migration schema
30-
if err != nil {
31-
log.Warn().Err(err).Msg("webhook uniqueness check failed")
32-
return nil // non-blocking: allow save on lookup failure
33-
}
34-
if existing != nil && existing.ID != excludeID {
35-
return errWebhookTokenDuplicate
36-
}
37-
return nil
38-
}
39-
4018
// ── Test Run ────────────────────────────────────────────────────────────
4119

4220
// TestRun performs a dry-run of an automation: evaluates the trigger snapshot,
@@ -630,17 +608,6 @@ func validateActionConfig(cfg action.ActionConfig) error {
630608
}
631609
}
632610

633-
//nolint:unused // pre-existing var retained pending follow-up cleanup
634-
var errWebhookTokenDuplicate = &duplicateTokenError{}
635-
636-
//nolint:unused // pre-existing type retained pending follow-up cleanup
637-
type duplicateTokenError struct{}
638-
639-
//nolint:unused // pre-existing func retained pending follow-up cleanup
640-
func (e *duplicateTokenError) Error() string {
641-
return "webhook_token is already in use by another automation"
642-
}
643-
644611
// scrubWebhookSecrets removes webhook token fields from shared exports.
645612
func scrubWebhookSecrets(raw json.RawMessage) json.RawMessage {
646613
var m map[string]interface{}

internal/api/battery_cells_handler.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,3 @@ func (h *BatteryCellsHandler) getHistory(ctx context.Context, vehicleID int64) [
298298
return points
299299
}
300300

301-
// frontendCell matches the BatteryCell TypeScript interface.
302-
//nolint:unused // pre-existing type retained pending follow-up cleanup
303-
type frontendCell struct {
304-
CellID int `json:"cell_id"`
305-
Module int `json:"module"`
306-
Voltage float64 `json:"voltage"`
307-
Temperature float64 `json:"temperature"`
308-
}

internal/api/battery_handler.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ func (h *BatteryHandler) Report(w http.ResponseWriter, r *http.Request) {
6363

6464
{
6565
const nominalCapacity = 75000.0
66-
//nolint:unused // pre-existing const retained pending follow-up cleanup
67-
const nominalRangeKm = 531.0
6866

6967
if h.state != nil {
7068
val, err := h.state.SignalAt(r.Context(), vehicleID, "EnergyRemaining", queryTime)

internal/api/chatbot_handler.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"strings"
87

98
"github.com/ev-dev-labs/teslasync/internal/database"
109
"github.com/ev-dev-labs/teslasync/internal/service"
@@ -85,43 +84,6 @@ func (h *ChatbotHandler) vehicleLocationLine(ctx context.Context, vehicleID int6
8584
return fmt.Sprintf("- **%s**: %.5f, %.5f", name, lat, lon), nil
8685
}
8786

88-
// queryVehicleLocation answers "where is my car?" / "show me the location"
89-
// fleet-wide. For every vehicle owned by the user it derives the most
90-
// recent Latitude/Longitude pair via vehicleLocationLine (which itself
91-
// goes through signal.LiveStateReader) — never via a raw snapshot-table
92-
// lookup against `positions`, which would miss the last-known coordinates
93-
// for a vehicle that has been parked beyond the snapshot lookback window.
94-
//nolint:unused // pre-existing func retained pending follow-up cleanup
95-
func (h *ChatbotHandler) queryVehicleLocation(ctx context.Context) string {
96-
if h.vehicleSvc == nil || h.live == nil {
97-
return "I couldn't retrieve location info right now."
98-
}
99-
vehicles, err := h.vehicleSvc.VehicleRepo().GetAll(ctx)
100-
if err != nil {
101-
return "I couldn't retrieve location info right now."
102-
}
103-
104-
var lines []string
105-
for _, v := range vehicles {
106-
if v == nil {
107-
continue
108-
}
109-
name := v.DisplayName
110-
if name == "" {
111-
name = "Unknown"
112-
}
113-
line, err := h.vehicleLocationLine(ctx, v.ID, name)
114-
if err != nil {
115-
return "I couldn't retrieve location info right now."
116-
}
117-
lines = append(lines, line)
118-
}
119-
if len(lines) == 0 {
120-
return "No vehicles found. Sync your fleet first."
121-
}
122-
return "**Vehicle Location:**\n" + strings.Join(lines, "\n")
123-
}
124-
12587
// toFloat64 normalizes a signal.SignalValue (which is `any`) into a float64.
12688
// signal_log payloads can land as float64 (numeric column) or other numeric
12789
// kinds depending on which storage path the value came in on, so the helper

internal/api/export_handler.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -551,22 +551,3 @@ func ptrFloat(p *float64) float64 {
551551
return 0
552552
}
553553

554-
// ptrFloatMpsToMphAPI converts a nullable SI speed value (m/s) to mph for
555-
// the legacy CSV/JSON export shape served by the public /exports endpoints.
556-
// Slice 4 of phase-48 will rename the export column to max_speed_mps and
557-
// drop this conversion.
558-
//nolint:unused // pre-existing func retained pending follow-up cleanup
559-
func ptrFloatMpsToMphAPI(p *float64) float64 {
560-
if p == nil {
561-
return 0
562-
}
563-
return *p / 0.44704
564-
}
565-
566-
//nolint:unused // pre-existing func retained pending follow-up cleanup
567-
func ptrInt16(p *int16) int {
568-
if p != nil {
569-
return int(*p)
570-
}
571-
return 0
572-
}

internal/api/middleware.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,3 @@ func TracingMiddleware(next http.Handler) http.Handler {
215215
)
216216
}
217217

218-
//nolint:unused // pre-existing func retained pending follow-up cleanup
219-
func tracedTransport(base http.RoundTripper) http.RoundTripper {
220-
if base == nil {
221-
base = http.DefaultTransport
222-
}
223-
return otelhttp.NewTransport(base)
224-
}

internal/api/polling_handler.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package api
22

33
import (
4-
"encoding/json"
54
"net/http"
65
"strconv"
76

@@ -156,16 +155,6 @@ func pollEngineConfig(engine *polling.PollEngine) http.HandlerFunc {
156155
}
157156
}
158157

159-
// writeJSON is a helper that writes JSON responses.
160-
// If the api package already has one, this will be a duplicate — but it's
161-
// defined here as a fallback to avoid import cycles.
162-
//nolint:unused // pre-existing func retained pending follow-up cleanup
163-
func writeJSONPolling(w http.ResponseWriter, status int, data interface{}) {
164-
w.Header().Set("Content-Type", "application/json")
165-
w.WriteHeader(status)
166-
json.NewEncoder(w).Encode(data) //nolint:errcheck
167-
}
168-
169158
// POST /api/v1/polling/demo — seeds the engine with realistic test data so
170159
// the dashboard can be previewed without an authenticated Tesla account.
171160
func pollEngineDemo(engine *polling.PollEngine) http.HandlerFunc {

internal/api/share_handler.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -324,62 +324,6 @@ func (h *ShareHandler) buildPublicProfiles(ctx context.Context, resp *publicShar
324324

325325
const clipPoints = 3 // number of points to clip from start/end for privacy
326326

327-
//nolint:unused // pre-existing func retained pending follow-up cleanup
328-
func (h *ShareHandler) buildFromTelemetry(resp *publicShareResponse, readings []*models.DriveTelemetryReading, share *models.ShareToken) {
329-
n := len(readings)
330-
if n <= clipPoints*2 {
331-
return
332-
}
333-
334-
// Clip start and end points for privacy
335-
clipped := readings[clipPoints : n-clipPoints]
336-
337-
var cumulativeDistM float64
338-
var prevLat, prevLng float64
339-
340-
for i, tp := range clipped {
341-
lat := derefFloat(tp.Latitude)
342-
lng := derefFloat(tp.Longitude)
343-
344-
if lat == 0 && lng == 0 {
345-
continue
346-
}
347-
348-
// Accumulate distance
349-
if i > 0 && prevLat != 0 {
350-
cumulativeDistM += haversineKm(prevLat, prevLng, lat, lng) * 1000.0
351-
}
352-
prevLat, prevLng = lat, lng
353-
354-
if share.IncludeMap {
355-
resp.MapPoints = append(resp.MapPoints, publicMapPoint{Lat: lat, Lng: lng})
356-
}
357-
358-
if tp.Elevation != nil {
359-
resp.ElevationProfile = append(resp.ElevationProfile, publicElevationPoint{
360-
DistanceM: cumulativeDistM,
361-
ElevationM: *tp.Elevation,
362-
})
363-
}
364-
365-
if share.IncludeSpeed && tp.Speed != nil {
366-
resp.SpeedProfile = append(resp.SpeedProfile, publicSpeedPoint{
367-
DistanceM: cumulativeDistM,
368-
SpeedMps: *tp.Speed * 0.44704,
369-
})
370-
}
371-
372-
if share.IncludeTelemetry {
373-
resp.Telemetry = append(resp.Telemetry, publicTelemetryPoint{
374-
DistanceM: cumulativeDistM,
375-
BatteryLevel: tp.BatteryLevel,
376-
Power: tp.Power,
377-
Elevation: tp.Elevation,
378-
})
379-
}
380-
}
381-
}
382-
383327
func (h *ShareHandler) buildFromPositions(resp *publicShareResponse, positions []models.Position, share *models.ShareToken) {
384328
n := len(positions)
385329
if n <= clipPoints*2 {

0 commit comments

Comments
 (0)