Skip to content

Commit 34bd547

Browse files
committed
lint fix
1 parent c0d3bb3 commit 34bd547

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

each_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ func TestEach(t *testing.T) {
4343

4444
func TestEachWithContext(t *testing.T) {
4545
rule := Each(WithContext(func(ctx context.Context, value interface{}) error {
46-
if !strings.Contains(value.(string), ctx.Value("contains").(string)) {
46+
if !strings.Contains(value.(string), ctx.Value(contains).(string)) {
4747
return errors.New("unexpected value")
4848
}
4949
return nil
5050
}))
51-
ctx1 := context.WithValue(context.Background(), "contains", "abc")
52-
ctx2 := context.WithValue(context.Background(), "contains", "xyz")
51+
ctx1 := context.WithValue(context.Background(), contains, "abc")
52+
ctx2 := context.WithValue(context.Background(), contains, "xyz")
5353

5454
tests := []struct {
5555
tag string

when.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@ func (r WhenRule) ValidateWithContext(ctx context.Context, value interface{}) er
2828
if r.condition {
2929
if ctx == nil {
3030
return Validate(value, r.rules...)
31-
} else {
32-
return ValidateWithContext(ctx, value, r.rules...)
3331
}
32+
return ValidateWithContext(ctx, value, r.rules...)
3433
}
3534

3635
if ctx == nil {
3736
return Validate(value, r.elseRules...)
38-
} else {
39-
return ValidateWithContext(ctx, value, r.elseRules...)
4037
}
38+
return ValidateWithContext(ctx, value, r.elseRules...)
4139
}
4240

4341
// Else returns a validation rule that executes the given list of rules when the condition is false.

when_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,21 @@ func TestWhen(t *testing.T) {
5757
}
5858
}
5959

60+
type ctxKey int
61+
62+
const (
63+
contains ctxKey = iota
64+
)
65+
6066
func TestWhenWithContext(t *testing.T) {
6167
rule := WithContext(func(ctx context.Context, value interface{}) error {
62-
if !strings.Contains(value.(string), ctx.Value("contains").(string)) {
68+
if !strings.Contains(value.(string), ctx.Value(contains).(string)) {
6369
return errors.New("unexpected value")
6470
}
6571
return nil
6672
})
67-
ctx1 := context.WithValue(context.Background(), "contains", "abc")
68-
ctx2 := context.WithValue(context.Background(), "contains", "xyz")
73+
ctx1 := context.WithValue(context.Background(), contains, "abc")
74+
ctx2 := context.WithValue(context.Background(), contains, "xyz")
6975

7076
tests := []struct {
7177
tag string

0 commit comments

Comments
 (0)