Skip to content

Commit 91814fe

Browse files
erraggyclaude
andauthored
chore: resolve SA5011 staticcheck warnings in test files (#364)
Replace `if x == nil { t.Fatal(...) }` guard pattern with `require.NotNil(t, x, ...)`. The old pattern confuses newer staticcheck (Go 1.26+) which doesn't track `testing.T.Fatal` as noreturn in all cases, flagging subsequent dereferences as possible nil dereferences. Files already import testify/require so this is a minimal mechanical change with no behavior difference — `require.NotNil` calls `t.FailNow()` under the hood. Affected: - differ/differ_test.go (1 site) - validator/refs_test.go (1 site) - validator/validator_test.go (3 sites) Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent a6e2307 commit 91814fe

3 files changed

Lines changed: 5 additions & 15 deletions

File tree

differ/differ_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import (
1010

1111
func TestDifferNew(t *testing.T) {
1212
d := New()
13-
if d == nil {
14-
t.Fatal("Expected non-nil Differ")
15-
}
13+
require.NotNil(t, d, "Expected non-nil Differ")
1614

1715
if d.Mode != ModeSimple {
1816
t.Errorf("Expected default mode to be ModeSimple, got %d", d.Mode)

validator/refs_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,7 @@ components:
281281
t.Fatalf("Validate failed: %v", err)
282282
}
283283

284-
if result == nil {
285-
t.Fatal("Expected result, got nil")
286-
}
284+
require.NotNil(t, result, "Expected result, got nil")
287285

288286
hasRefError := false
289287
for _, validationErr := range result.Errors {

validator/validator_test.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import (
1515
// TestValidatorNew tests the New constructor
1616
func TestValidatorNew(t *testing.T) {
1717
v := New()
18-
if v == nil {
19-
t.Fatal("New() returned nil")
20-
}
18+
require.NotNil(t, v, "New() returned nil")
2119
if !v.IncludeWarnings {
2220
t.Error("Expected IncludeWarnings to be true by default")
2321
}
@@ -374,9 +372,7 @@ func TestCircularSchemaReferences(t *testing.T) {
374372
}
375373

376374
// Validation should not crash on circular schemas
377-
if result == nil {
378-
t.Fatal("Expected result, got nil")
379-
}
375+
require.NotNil(t, result, "Expected result, got nil")
380376

381377
t.Logf("Circular schema validation completed with %d errors, %d warnings", result.ErrorCount, result.WarningCount)
382378
}
@@ -394,9 +390,7 @@ func TestDeeplyNestedSchemas(t *testing.T) {
394390
}
395391

396392
// Validation should complete without stack overflow
397-
if result == nil {
398-
t.Fatal("Expected result, got nil")
399-
}
393+
require.NotNil(t, result, "Expected result, got nil")
400394

401395
t.Logf("Deeply nested schema validation completed with %d errors, %d warnings", result.ErrorCount, result.WarningCount)
402396
}

0 commit comments

Comments
 (0)