Skip to content

Commit 3e9fdeb

Browse files
committed
fixup! feat!: Refactor request context
1 parent 9785804 commit 3e9fdeb

3 files changed

Lines changed: 10 additions & 15 deletions

File tree

tools/extraneousnew/extraneousnew.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ func inspectBlock(pass *analysis.Pass, block *ast.BlockStmt) {
196196
}
197197

198198
var targetArg ast.Expr
199-
if fnName == "Do" && len(call.Args) == 3 {
200-
targetArg = call.Args[2]
199+
if fnName == "Do" && len(call.Args) == 2 {
200+
targetArg = call.Args[1]
201201
} else if fnName == "Decode" && len(call.Args) == 1 {
202202
targetArg = call.Args[0]
203203
}
@@ -251,8 +251,8 @@ func lookAhead(pass *analysis.Pass, block *ast.BlockStmt, startIndex int, lhsIde
251251

252252
fnName := getFunctionName(call.Fun)
253253
var targetArg ast.Expr
254-
if fnName == "Do" && len(call.Args) == 3 {
255-
targetArg = call.Args[2]
254+
if fnName == "Do" && len(call.Args) == 2 {
255+
targetArg = call.Args[1]
256256
} else if fnName == "Decode" && len(call.Args) == 1 {
257257
targetArg = call.Args[0]
258258
}

tools/extraneousnew/testdata/src/has-warnings/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package main
77

88
import (
9-
"context"
109
"encoding/json"
1110
"net/http"
1211
"testing"
@@ -18,7 +17,7 @@ type T struct {
1817

1918
type Client struct{}
2019

21-
func (c *Client) Do(ctx context.Context, req any, v any) (any, error) {
20+
func (c *Client) Do(req any, v any) (any, error) {
2221
return nil, nil
2322
}
2423

@@ -28,7 +27,7 @@ type Service struct {
2827

2928
func assertNilError(t *testing.T, err error) {}
3029

31-
func (s *Service) TestMethod(ctx context.Context, req any, r *http.Request, t *testing.T) {
30+
func (s *Service) TestMethod(req any, r *http.Request, t *testing.T) {
3231
v1 := new(T)
3332
s.client.Do(req, v1) // want "use 'var v1 [*]T' and pass '&v1' instead"
3433

tools/extraneousnew/testdata/src/no-warnings/main.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,21 @@
55

66
package main
77

8-
import (
9-
"context"
10-
)
11-
128
type T struct {
139
Field string
1410
}
1511

1612
type Client struct{}
1713

18-
func (c *Client) Do(ctx context.Context, req any, v any) (any, error) {
14+
func (c *Client) Do(req any, v any) (any, error) {
1915
return nil, nil
2016
}
2117

2218
type Receiver struct {
2319
client *Client
2420
}
2521

26-
func (s *Receiver) TestMethod(ctx context.Context, req any) {
22+
func (s *Receiver) TestMethod(req any) {
2723
// Proper usage: var pointer and pass &v
2824
var v1 *T
2925
s.client.Do(req, &v1)
@@ -44,12 +40,12 @@ func (s *Receiver) TestMethod(ctx context.Context, req any) {
4440
s.client.Do(req, &v11)
4541
}
4642

47-
func (s *Receiver) MethodNameToIgnore(ctx context.Context, req any) {
43+
func (s *Receiver) MethodNameToIgnore(req any) {
4844
v := new(T)
4945
s.client.Do(req, v)
5046
}
5147

52-
func (s *Receiver) unexportedMethod(ctx context.Context, req any) {
48+
func (s *Receiver) unexportedMethod(req any) {
5349
v := new(T)
5450
s.client.Do(req, v) // Should be ignored because unexported.
5551
}

0 commit comments

Comments
 (0)