SA1012: fix tests for suggested fixes
Closes: [via git-merge-pr]
+-- use context.Background --
package pkg
import "context"
@@ -22,3 +23,28 @@ func fn3() {
_ = (func())(nil)
(*T).Foo(nil)
}
+-- use context.TODO --
+package pkg
+
+import "context"
+
+func fn1(ctx context.Context) {}
+func fn2(x string, ctx context.Context) {}
+func fn4() {}
+
+type T struct{}
+
+func (*T) Foo() {}
+
+func fn3() {
+ fn1(context.TODO()) // want `do not pass a nil Context`
+ fn1(context.TODO())
+ fn2("", nil)
+ fn4()
+
+ // don't flag this conversion
+ _ = (func(context.Context))(nil)
+ // and don't crash on these
+ _ = (func())(nil)
+ (*T).Foo(nil)
+}
