forked from mgechev/revive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext-as-argument.go
54 lines (38 loc) · 1.63 KB
/
context-as-argument.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Test that context.Context is the first arg to a function.
// Package foo ...
package foo
import (
"context"
"testing"
)
// AllowedBeforeType is a type that is configured to be allowed before context.Context
type AllowedBeforeType string
// AllowedBeforeStruct is a type that is configured to be allowed before context.Context
type AllowedBeforeStruct struct{}
// AllowedBeforePtrStruct is a type that is configured to be allowed before context.Context
type AllowedBeforePtrStruct struct{}
// A proper context.Context location
func x(ctx context.Context) { // ok
}
// A proper context.Context location
func x(ctx context.Context, s string) { // ok
}
// *testing.T is permitted in the linter config for the test
func x(t *testing.T, ctx context.Context) { // ok
}
func x(_ AllowedBeforeType, _ AllowedBeforeType, ctx context.Context) { // ok
}
func x(_, _ AllowedBeforeType, ctx context.Context) { // ok
}
func x(_ *AllowedBeforePtrStruct, ctx context.Context) { // ok
}
func x(_ AllowedBeforePtrStruct, ctx context.Context) { // MATCH /context.Context should be the first parameter of a function/
}
// An invalid context.Context location
func y(s string, ctx context.Context) { // MATCH /context.Context should be the first parameter of a function/
}
// An invalid context.Context location with more than 2 args
func y(s string, r int, ctx context.Context, x int) { // MATCH /context.Context should be the first parameter of a function/
}
func y(ctx1 context.Context, ctx2 context.Context, x int) {}
func y(ctx1 context.Context, ctx2 context.Context, x int, ctx3 context.Context) {} // MATCH /context.Context should be the first parameter of a function/