Skip to content

Commit 5041ec2

Browse files
cvclaude
andcommitted
feat: Enable 8 additional linters and fix type assertions
New linters enabled: - asciicheck, bidichk (security) - errcheck, errname, forcetypeassert, ineffassign (bug finders) - staticcheck, unused (code quality) Fixed 9 unchecked type assertions in confirm.go by adding proper ok checks with error returns. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0376701 commit 5041ec2

2 files changed

Lines changed: 57 additions & 12 deletions

File tree

.golangci.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@ version: "2"
33
linters:
44
enable:
55
# Bug finders
6+
- asciicheck # Non-ASCII identifiers
7+
- bidichk # Dangerous unicode sequences
68
- bodyclose # HTTP response body closure
79
- durationcheck # Duration multiplication bugs
810
- embeddedstructfieldcheck # Embedded struct field access issues
11+
- errcheck # Unchecked errors
912
- errorlint # Error wrapping issues
1013
- errchkjson # JSON encoding error checks
14+
- errname # Error naming conventions
1115
- fatcontext # Context misuse in loops
16+
- forcetypeassert # Unchecked type assertions
17+
- ineffassign # Ineffective assignments
1218
- nilerr # Returns nil even when error set
1319
- noctx # Missing context.Context usage
1420
- nosprintfhostport # URL construction bugs
21+
- staticcheck # Comprehensive static analysis
22+
- unused # Unused code
1523

1624
# Security
1725
- gosec # Security issues
@@ -70,10 +78,11 @@ linters:
7078
linters:
7179
- gocritic
7280
text: appendAssign
73-
# Test files can have repeated strings
81+
# Test files can have repeated strings and controlled type assertions
7482
- path: _test\.go
7583
linters:
7684
- goconst
85+
- forcetypeassert
7786
# Global variables - justified exclusions:
7887
# 1. Read-only lookup tables (RegionConfigs, screenSizes, androidVersionToSDK)
7988
- path: internal/api/auth\.go

internal/cli/confirm.go

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ func waitForDoorsLocked(
173173
pollInterval time.Duration,
174174
) confirmationResult {
175175
conditionChecker := func(status any) (bool, error) {
176-
vStatus := status.(*api.VehicleStatusResponse)
176+
vStatus, ok := status.(*api.VehicleStatusResponse)
177+
if !ok {
178+
return false, fmt.Errorf("unexpected status type: %T", status)
179+
}
180+
177181
doorStatus, err := vStatus.GetDoorsInfo()
178182
if err != nil {
179183
return false, err
@@ -195,7 +199,11 @@ func waitForDoorsUnlocked(
195199
pollInterval time.Duration,
196200
) confirmationResult {
197201
conditionChecker := func(status any) (bool, error) {
198-
vStatus := status.(*api.VehicleStatusResponse)
202+
vStatus, ok := status.(*api.VehicleStatusResponse)
203+
if !ok {
204+
return false, fmt.Errorf("unexpected status type: %T", status)
205+
}
206+
199207
doorStatus, err := vStatus.GetDoorsInfo()
200208
if err != nil {
201209
return false, err
@@ -217,7 +225,11 @@ func waitForEngineRunning(
217225
pollInterval time.Duration,
218226
) confirmationResult {
219227
conditionChecker := func(status any) (bool, error) {
220-
evStatus := status.(*api.EVVehicleStatusResponse)
228+
evStatus, ok := status.(*api.EVVehicleStatusResponse)
229+
if !ok {
230+
return false, fmt.Errorf("unexpected status type: %T", status)
231+
}
232+
221233
hvacInfo, err := evStatus.GetHvacInfo()
222234
if err != nil {
223235
return false, err
@@ -239,7 +251,11 @@ func waitForEngineStopped(
239251
pollInterval time.Duration,
240252
) confirmationResult {
241253
conditionChecker := func(status any) (bool, error) {
242-
evStatus := status.(*api.EVVehicleStatusResponse)
254+
evStatus, ok := status.(*api.EVVehicleStatusResponse)
255+
if !ok {
256+
return false, fmt.Errorf("unexpected status type: %T", status)
257+
}
258+
243259
hvacInfo, err := evStatus.GetHvacInfo()
244260
if err != nil {
245261
return false, err
@@ -261,7 +277,11 @@ func waitForCharging(
261277
pollInterval time.Duration,
262278
) confirmationResult {
263279
conditionChecker := func(status any) (bool, error) {
264-
evStatus := status.(*api.EVVehicleStatusResponse)
280+
evStatus, ok := status.(*api.EVVehicleStatusResponse)
281+
if !ok {
282+
return false, fmt.Errorf("unexpected status type: %T", status)
283+
}
284+
265285
batteryInfo, err := evStatus.GetBatteryInfo()
266286
if err != nil {
267287
return false, err
@@ -283,7 +303,11 @@ func waitForNotCharging(
283303
pollInterval time.Duration,
284304
) confirmationResult {
285305
conditionChecker := func(status any) (bool, error) {
286-
evStatus := status.(*api.EVVehicleStatusResponse)
306+
evStatus, ok := status.(*api.EVVehicleStatusResponse)
307+
if !ok {
308+
return false, fmt.Errorf("unexpected status type: %T", status)
309+
}
310+
287311
batteryInfo, err := evStatus.GetBatteryInfo()
288312
if err != nil {
289313
return false, err
@@ -309,7 +333,11 @@ func waitForHvacOn(
309333
pollInterval time.Duration,
310334
) confirmationResult {
311335
conditionChecker := func(status any) (bool, error) {
312-
evStatus := status.(*api.EVVehicleStatusResponse)
336+
evStatus, ok := status.(*api.EVVehicleStatusResponse)
337+
if !ok {
338+
return false, fmt.Errorf("unexpected status type: %T", status)
339+
}
340+
313341
hvacInfo, err := evStatus.GetHvacInfo()
314342
if err != nil {
315343
return false, err
@@ -331,7 +359,11 @@ func waitForHvacOff(
331359
pollInterval time.Duration,
332360
) confirmationResult {
333361
conditionChecker := func(status any) (bool, error) {
334-
evStatus := status.(*api.EVVehicleStatusResponse)
362+
evStatus, ok := status.(*api.EVVehicleStatusResponse)
363+
if !ok {
364+
return false, fmt.Errorf("unexpected status type: %T", status)
365+
}
366+
335367
hvacInfo, err := evStatus.GetHvacInfo()
336368
if err != nil {
337369
return false, err
@@ -356,18 +388,22 @@ func waitForHvacSettings(
356388
pollInterval time.Duration,
357389
) confirmationResult {
358390
conditionChecker := func(status any) (bool, error) {
359-
evStatus := status.(*api.EVVehicleStatusResponse)
391+
evStatus, ok := status.(*api.EVVehicleStatusResponse)
392+
if !ok {
393+
return false, fmt.Errorf("unexpected status type: %T", status)
394+
}
395+
360396
hvacInfo, err := evStatus.GetHvacInfo()
361397
if err != nil {
362398
return false, err
363399
}
364400

365-
// Check temperature with tolerance of 0.5C
401+
// Check temperature with tolerance of 0.5C.
366402
const tempTolerance = 0.5
367403
tempMatch := hvacInfo.TargetTempC >= targetTemp-tempTolerance &&
368404
hvacInfo.TargetTempC <= targetTemp+tempTolerance
369405

370-
// Check defroster settings
406+
// Check defroster settings.
371407
defrostersMatch := hvacInfo.FrontDefroster == frontDefroster &&
372408
hvacInfo.RearDefroster == rearDefroster
373409

0 commit comments

Comments
 (0)