Skip to content

Commit 4bfa4f7

Browse files
authored
adjust lint config, and fix several lint warnings (and rebuild the example wasm) (#64)
1 parent 4b2686c commit 4bfa4f7

30 files changed

+223
-225
lines changed

.golangci.yml

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,27 @@ linters:
1212
- noctx # Finds sending http request without context.Context
1313
- prealloc # Temporarily disable until slice allocation issues are fixed
1414
enable:
15-
- bodyclose # Checks HTTP response body is closed
16-
- contextcheck # Check whether the function uses a non-inherited context
17-
- dupl # Find duplicate code
18-
- dupword # Find duplicate words in comments and strings
19-
- errcheck
20-
- errorlint # Check error handling
21-
- misspell # Find commonly misspelled English words
22-
- unconvert # Remove unnecessary type conversions
23-
- reassign # Checks that package variables are not reassigned
24-
- tagalign # Check that struct tags are well aligned
25-
- nilerr # Finds code that returns nil even if it checks that the error is not nil
26-
- nolintlint # Checks for invalid or missing nolint directives
27-
- whitespace # Check for unnecessary whitespace
28-
- thelper # Detects test helpers which should start with t.Helper()
29-
- govet # Examines Go source code and reports suspicious constructs
30-
- ineffassign # Detects when assignments to existing variables are not used
31-
- staticcheck # Staticcheck is a go linter
32-
- unused # Checks for unused code
15+
- bodyclose # Ensure HTTP response bodies are closed
16+
- contextcheck # Ensure functions use a non-inherited context
17+
- dupl # Detect duplicate code
18+
- dupword # Detect duplicate words in comments/strings
19+
- errcheck # Check for unchecked errors
20+
- errorlint # Enforce idiomatic error handling
21+
- govet # Report suspicious constructs
22+
- ineffassign # Detect unused variable assignments
23+
- misspell # Detect misspelled English words
24+
- nilerr # Detect returning nil after error checks
25+
- nolintlint # Check for invalid/missing nolint directives
26+
- reassign # Prevent package variable reassignment
27+
- staticcheck # Advanced static analysis
28+
- tagalign # Check struct tag alignment
29+
- tagliatelle # Enforce struct tag formatting
30+
- testifylint # Avoid common testify mistakes
31+
- thelper # Ensure test helpers use t.Helper()
32+
- unconvert # Remove unnecessary type conversions
33+
- usetesting # Detects when some calls can be replaced by methods from the testing package
34+
- unused # Detect unused code
35+
- whitespace # Detect unnecessary whitespace
3336
settings:
3437
errcheck:
3538
check-blank: true
@@ -41,14 +44,25 @@ linters:
4144
errorf: true
4245
asserts: true
4346
comparison: true
47+
tagalign:
48+
strict: true
49+
order:
50+
- json
51+
- toml
52+
- yaml
53+
- xml
54+
- env_interpolation
55+
usetesting:
56+
os-temp-dir: true
57+
context-background: true
58+
context-todo: true
4459

4560
formatters:
4661
enable:
4762
- gci
4863
- gofmt
4964
- goimports
5065
- gofumpt
51-
- golines
5266

5367
issues:
5468
max-issues-per-linter: 20

engines/extism/adapters/sdkAdapters_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@ func TestInterfaceImplementation(t *testing.T) {
2424
// For the sdkCompiledPluginAdapter and sdkPluginAdapter implementations, we rely on
2525
// the Extism SDK's types, so we don't need exhaustive tests for this wrapper code.
2626

27-
func TestAdapterCorrectlyImplementsInterfaces(t *testing.T) {
28-
// These tests verify that the methods of the interfaces correctly match
29-
// the methods of the SDK types. If there's a mismatch, Go won't compile.
30-
//
31-
// We don't need to test the implementation since it's just directly
32-
// calling the SDK's methods. We're just verifying the types at compile time.
33-
34-
// Implicitly test this with the interface check above
35-
assert.True(t, true, "Adapters correctly implement their interfaces")
36-
}
37-
3827
func TestNilPlugin(t *testing.T) {
3928
// Test that NewCompiledPluginAdapter returns nil when given a nil plugin
4029
adapter := NewCompiledPluginAdapter(nil)

engines/extism/compiler/internal/compile/compile_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ func testFunctions(t *testing.T, instance adapters.PluginInstance) {
181181
assertFunc: func(t *testing.T, output []byte) {
182182
t.Helper()
183183
var result struct {
184-
RequestID string `json:"request_id"`
185-
ProcessedAt string `json:"processed_at"`
184+
RequestID string `json:"requestId"`
185+
ProcessedAt string `json:"processedAt"`
186186
Results map[string]any `json:"results"`
187-
TagCount int `json:"tag_count"`
188-
MetaCount int `json:"meta_count"`
189-
IsActive bool `json:"is_active"`
187+
TagCount int `json:"tagCount"`
188+
MetaCount int `json:"metaCount"`
189+
IsActive bool `json:"isActive"`
190190
Summary string `json:"summary"`
191191
}
192192
require.NoError(t, json.Unmarshal(output, &result))

engines/extism/compiler/options_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestCompilerOptions_Options(t *testing.T) {
5353

5454
t.Run("empty value", func(t *testing.T) {
5555
c := &Compiler{entryPointName: ""}
56-
require.Equal(t, "", c.GetEntryPointName())
56+
require.Empty(t, c.GetEntryPointName())
5757
})
5858

5959
t.Run("with defaults", func(t *testing.T) {
@@ -617,7 +617,7 @@ func TestCompilerOptions(t *testing.T) {
617617
c2 := &Compiler{
618618
entryPointName: "",
619619
}
620-
require.Equal(t, "", c2.GetEntryPointName())
620+
require.Empty(t, c2.GetEntryPointName())
621621
})
622622
})
623623

engines/extism/evaluator/evaluator_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func TestEvaluator_Evaluate(t *testing.T) {
178178
require.Contains(t, resultMap, "result")
179179
require.Equal(t, "success", resultMap["result"])
180180
require.Contains(t, resultMap, "value")
181-
require.Equal(t, float64(42), resultMap["value"])
181+
require.InDelta(t, float64(42), resultMap["value"], 0.0001)
182182
})
183183

184184
// Test successful string response
@@ -398,8 +398,7 @@ func TestEvaluator_Evaluate(t *testing.T) {
398398
// Call Eval, which should be cancelled during execution
399399
result, err := evaluator.Eval(ctx)
400400

401-
// Should get a cancellation error
402-
assert.Error(t, err)
401+
require.Error(t, err, "Expected cancellation error")
403402
assert.Nil(t, result)
404403
assert.Contains(t, err.Error(), "execution")
405404

@@ -588,19 +587,18 @@ func TestEvaluator_Evaluate(t *testing.T) {
588587
"Expected the mock instance to be called",
589588
)
590589

591-
// Check for expected errors
592590
if tt.wantErr {
593-
assert.Error(t, err)
591+
require.Error(t, err)
594592
if tt.errContains != "" {
595593
assert.Contains(t, err.Error(), tt.errContains)
596594
}
597595
} else {
598-
assert.NoError(t, err)
596+
require.NoError(t, err)
599597
assert.NotNil(t, result)
600598
}
601599

602600
// Execution time should always be measured
603-
assert.Greater(t, execTime.Nanoseconds(), int64(0))
601+
assert.Positive(t, execTime.Nanoseconds())
604602
})
605603
}
606604
})

engines/extism/internal/converters_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func TestConvertToExtismFormat(t *testing.T) {
8484
// Handle type conversions that happen during JSON marshaling
8585
if intVal, isInt := expectedVal.(int); isInt {
8686
// JSON unmarshaling converts numbers to float64
87-
assert.Equal(t, float64(intVal), checkData[k])
87+
assert.InDelta(t, float64(intVal), checkData[k], 0.0001)
8888
} else if _, isIntSlice := expectedVal.([]int); isIntSlice {
8989
// Skip int slice checks (arrays become []any)
9090
} else if _, isSlice := expectedVal.([]any); !isSlice {

engines/extism/internal/jsonHelpers_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ func TestFixJSONNumberTypes(t *testing.T) {
7777
assert.True(t, ok, "Result should be a map")
7878

7979
// Check that the values were converted to float64
80-
assert.Equal(t, float64(19.99), mapResult["price"])
81-
assert.Equal(t, float64(4.5), mapResult["rating"])
82-
assert.Equal(t, float64(75.5), mapResult["percentage"])
80+
assert.InDelta(t, float64(19.99), mapResult["price"], 0.0001)
81+
assert.InDelta(t, float64(4.5), mapResult["rating"], 0.0001)
82+
assert.InDelta(t, float64(75.5), mapResult["percentage"], 0.0001)
8383
assert.IsType(t, float64(0), mapResult["price"])
8484
assert.IsType(t, float64(0), mapResult["rating"])
8585
assert.IsType(t, float64(0), mapResult["percentage"])
@@ -113,7 +113,7 @@ func TestFixJSONNumberTypes(t *testing.T) {
113113
stats, ok := user["stats"].(map[string]any)
114114
assert.True(t, ok, "stats should be a map")
115115
assert.Equal(t, int(42), stats["login_count"])
116-
assert.Equal(t, float64(95.5), stats["score"])
116+
assert.InDelta(t, float64(95.5), stats["score"], 0.0001)
117117
})
118118

119119
t.Run("handles slices", func(t *testing.T) {
@@ -142,7 +142,7 @@ func TestFixJSONNumberTypes(t *testing.T) {
142142
itemMap, ok := sliceResult[3].(map[string]any)
143143
assert.True(t, ok, "Item at index 3 should be a map")
144144
assert.Equal(t, int(123), itemMap["item_id"])
145-
assert.Equal(t, float64(9.99), itemMap["price"])
145+
assert.InDelta(t, float64(9.99), itemMap["price"], 0.0001)
146146
})
147147

148148
t.Run("handles nested slices", func(t *testing.T) {
@@ -177,13 +177,13 @@ func TestFixJSONNumberTypes(t *testing.T) {
177177
product1, ok := products[0].(map[string]any)
178178
assert.True(t, ok, "First product should be a map")
179179
assert.Equal(t, int(1), product1["product_id"])
180-
assert.Equal(t, float64(19.99), product1["price"])
180+
assert.InDelta(t, float64(19.99), product1["price"], 0.0001)
181181

182182
// Check second product
183183
product2, ok := products[1].(map[string]any)
184184
assert.True(t, ok, "Second product should be a map")
185185
assert.Equal(t, int(2), product2["product_id"])
186-
assert.Equal(t, float64(29.99), product2["price"])
186+
assert.InDelta(t, float64(29.99), product2["price"], 0.0001)
187187
})
188188

189189
t.Run("handles invalid numbers gracefully", func(t *testing.T) {

engines/extism/wasmdata/examples/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ type Request struct {
2222

2323
// Response represents a complex output object
2424
type Response struct {
25-
RequestID string `json:"request_id"`
26-
ProcessedAt string `json:"processed_at"`
25+
RequestID string `json:"requestId"`
26+
ProcessedAt string `json:"processedAt"`
2727
Results map[string]any `json:"results"`
28-
TagCount int `json:"tag_count"`
29-
MetaCount int `json:"meta_count"`
30-
IsActive bool `json:"is_active"`
28+
TagCount int `json:"tagCount"`
29+
MetaCount int `json:"metaCount"`
30+
IsActive bool `json:"isActive"`
3131
Summary string `json:"summary"`
3232
}
3333

engines/extism/wasmdata/integration_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ func TestExtismWasmIntegration(t *testing.T) {
209209
err = json.Unmarshal(output, &response)
210210
require.NoError(t, err, "Failed to parse complex response")
211211

212-
assert.Equal(t, "test-123", response["request_id"])
213-
assert.NotEmpty(t, response["processed_at"])
214-
assert.Equal(t, float64(3), response["tag_count"]) // JSON numbers are float64
215-
assert.Equal(t, float64(3), response["meta_count"])
212+
assert.Equal(t, "test-123", response["requestId"])
213+
assert.NotEmpty(t, response["processedAt"])
214+
assert.InDelta(t, float64(3), response["tagCount"], 0.0001) // JSON numbers are float64
215+
assert.InDelta(t, float64(3), response["metaCount"], 0.0001)
216216
assert.Contains(t, response["summary"], "test-123")
217217
})
218218

@@ -245,7 +245,7 @@ func TestExtismWasmIntegration(t *testing.T) {
245245
require.NoError(t, err, "Failed to parse vowel result")
246246

247247
assert.Equal(t, "Hello World", vowelResult["input"])
248-
assert.Equal(t, float64(3), vowelResult["count"]) // 3 vowels in "Hello World"
248+
assert.InDelta(t, float64(3), vowelResult["count"], 0.0001) // 3 vowels in "Hello World"
249249
})
250250

251251
t.Run("reverse_string function", func(t *testing.T) {
@@ -312,7 +312,7 @@ func TestExtismWasmIntegration(t *testing.T) {
312312
require.NoError(t, err, "Failed to parse vowel result")
313313

314314
assert.Equal(t, "Hello World", vowelResult["input"])
315-
assert.Equal(t, float64(3), vowelResult["count"]) // 3 vowels in "Hello World"
315+
assert.InDelta(t, float64(3), vowelResult["count"], 0.0001) // 3 vowels in "Hello World"
316316
})
317317

318318
t.Run("reverse_string_namespaced function", func(t *testing.T) {

engines/extism/wasmdata/main.wasm

-422 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)