Skip to content

Commit a271631

Browse files
committed
fix: remove duplicated reports
1 parent 46d2223 commit a271631

File tree

22 files changed

+24
-30
lines changed

22 files changed

+24
-30
lines changed

testdata/src/contextbackground/basic/basic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func Test_FuncLit_ExprStmt(t *testing.T) {
100100

101101
for _, test := range testCases {
102102
t.Run(test.desc, func(t *testing.T) {
103-
context.Background() // want `context\.Background\(\) could be replaced by t\.Context\(\) in .+` `context\.Background\(\) could be replaced by t\.Context\(\) in .+`
103+
context.Background() // want `context\.Background\(\) could be replaced by t\.Context\(\) in .+`
104104
})
105105
}
106106
}

testdata/src/contextbackground/dot/dot_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dot
22

33
import (
4-
"context"
54
. "context"
65
"errors"
76
"fmt"
@@ -81,7 +80,7 @@ func Test_GoStmt(t *testing.T) {
8180
}
8281

8382
func Test_GoStmt_arg(t *testing.T) {
84-
go func(ctx context.Context) {}(Background()) // want `context\.Background\(\) could be replaced by t\.Context\(\) in .+`
83+
go func(ctx Context) {}(Background()) // want `context\.Background\(\) could be replaced by t\.Context\(\) in .+`
8584
}
8685

8786
func Test_CallExpr_recursive(t *testing.T) {
@@ -101,7 +100,7 @@ func Test_FuncLit_ExprStmt(t *testing.T) {
101100

102101
for _, test := range testCases {
103102
t.Run(test.desc, func(t *testing.T) {
104-
Background() // want `context\.Background\(\) could be replaced by t\.Context\(\) in .+` `context\.Background\(\) could be replaced by t\.Context\(\) in .+`
103+
Background() // want `context\.Background\(\) could be replaced by t\.Context\(\) in .+`
105104
})
106105
}
107106
}
@@ -121,7 +120,7 @@ func Test_SwitchStmt_case(t *testing.T) {
121120
}
122121

123122
func Test_DeclStmt(t *testing.T) {
124-
var ctx context.Context = Background() // want `context\.Background\(\) could be replaced by t\.Context\(\) in .+`
123+
var ctx Context = Background() // want `context\.Background\(\) could be replaced by t\.Context\(\) in .+`
125124
_ = ctx
126125
}
127126

testdata/src/contextbackground/nottestfiles/nottestfiles.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func FunctionFuncLit_ExprStmt(t *testing.T) {
104104

105105
for _, test := range testCases {
106106
t.Run(test.desc, func(t *testing.T) {
107-
context.Background() // want `context\.Background\(\) could be replaced by t\.Context\(\) in .+` `context\.Background\(\) could be replaced by t\.Context\(\) in .+`
107+
context.Background() // want `context\.Background\(\) could be replaced by t\.Context\(\) in .+`
108108
})
109109
}
110110
}

testdata/src/contexttodo/basic/basic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func Test_FuncLit_ExprStmt(t *testing.T) {
100100

101101
for _, test := range testCases {
102102
t.Run(test.desc, func(t *testing.T) {
103-
context.TODO() // want `context\.TODO\(\) could be replaced by t\.Context\(\) in .+` `context\.TODO\(\) could be replaced by t\.Context\(\) in .+`
103+
context.TODO() // want `context\.TODO\(\) could be replaced by t\.Context\(\) in .+`
104104
})
105105
}
106106
}

testdata/src/contexttodo/dot/dot_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func Test_FuncLit_ExprStmt(t *testing.T) {
101101

102102
for _, test := range testCases {
103103
t.Run(test.desc, func(t *testing.T) {
104-
TODO() // want `context\.TODO\(\) could be replaced by t\.Context\(\) in .+` `context\.TODO\(\) could be replaced by t\.Context\(\) in .+`
104+
TODO() // want `context\.TODO\(\) could be replaced by t\.Context\(\) in .+`
105105
})
106106
}
107107
}

testdata/src/contexttodo/nottestfiles/nottestfiles.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func FunctionFuncLit_ExprStmt(t *testing.T) {
104104

105105
for _, test := range testCases {
106106
t.Run(test.desc, func(t *testing.T) {
107-
context.TODO() // want `context\.TODO\(\) could be replaced by t\.Context\(\) in .+` `context\.TODO\(\) could be replaced by t\.Context\(\) in .+`
107+
context.TODO() // want `context\.TODO\(\) could be replaced by t\.Context\(\) in .+`
108108
})
109109
}
110110
}

testdata/src/oschdir/basic/basic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func Test_FuncLit_ExprStmt(t *testing.T) {
101101

102102
for _, test := range testCases {
103103
t.Run(test.desc, func(t *testing.T) {
104-
os.Chdir("") // want `os\.Chdir\(\) could be replaced by t\.Chdir\(\) in .+` `os\.Chdir\(\) could be replaced by t\.Chdir\(\) in .+`
104+
os.Chdir("") // want `os\.Chdir\(\) could be replaced by t\.Chdir\(\) in .+`
105105
})
106106
}
107107
}

testdata/src/oschdir/dot/dot_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func Test_FuncLit_ExprStmt(t *testing.T) {
101101

102102
for _, test := range testCases {
103103
t.Run(test.desc, func(t *testing.T) {
104-
Chdir("") // want `os\.Chdir\(\) could be replaced by t\.Chdir\(\) in .+` `os\.Chdir\(\) could be replaced by t\.Chdir\(\) in .+`
104+
Chdir("") // want `os\.Chdir\(\) could be replaced by t\.Chdir\(\) in .+`
105105
})
106106
}
107107
}

testdata/src/oschdir/nottestfiles/nottestfiles.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func FunctionFuncLit_ExprStmt(t *testing.T) {
105105

106106
for _, test := range testCases {
107107
t.Run(test.desc, func(t *testing.T) {
108-
os.Chdir("") // want `os\.Chdir\(\) could be replaced by t\.Chdir\(\) in .+` `os\.Chdir\(\) could be replaced by t\.Chdir\(\) in .+`
108+
os.Chdir("") // want `os\.Chdir\(\) could be replaced by t\.Chdir\(\) in .+`
109109
})
110110
}
111111
}

testdata/src/oscreatetemp/basic/basic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func Test_FuncLit_ExprStmt(t *testing.T) {
7777

7878
for _, test := range testCases {
7979
t.Run(test.desc, func(t *testing.T) {
80-
os.CreateTemp("", "") // want `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+` `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+`
80+
os.CreateTemp("", "") // want `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+`
8181
})
8282
}
8383
}

testdata/src/oscreatetemp/dot/dot_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func Test_FuncLit_ExprStmt(t *testing.T) {
7777

7878
for _, test := range testCases {
7979
t.Run(test.desc, func(t *testing.T) {
80-
CreateTemp("", "") // want `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+` `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+`
80+
CreateTemp("", "") // want `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+`
8181
})
8282
}
8383
}

testdata/src/oscreatetemp/nottestfiles/nottestfiles_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func FunctionFuncLit_ExprStmt(t *testing.T) {
8181

8282
for _, test := range testCases {
8383
t.Run(test.desc, func(t *testing.T) {
84-
os.CreateTemp("", "") // want `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+` `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+`
84+
os.CreateTemp("", "") // want `os\.CreateTemp\("", \.\.\.\) could be replaced by os\.CreateTemp\(t\.TempDir\(\), \.\.\.\) in .+`
8585
})
8686
}
8787
}

testdata/src/osmkdirtemp/basic/basic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func Test_FuncLit_ExprStmt(t *testing.T) {
101101

102102
for _, test := range testCases {
103103
t.Run(test.desc, func(t *testing.T) {
104-
os.MkdirTemp("", "") // want `os\.MkdirTemp\(\) could be replaced by t\.TempDir\(\) in .+` `os\.MkdirTemp\(\) could be replaced by t\.TempDir\(\) in .+`
104+
os.MkdirTemp("", "") // want `os\.MkdirTemp\(\) could be replaced by t\.TempDir\(\) in .+`
105105
})
106106
}
107107
}

testdata/src/osmkdirtemp/dot/dot_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func Test_FuncLit_ExprStmt(t *testing.T) {
101101

102102
for _, test := range testCases {
103103
t.Run(test.desc, func(t *testing.T) {
104-
MkdirTemp("", "") // want `os\.MkdirTemp\(\) could be replaced by t\.TempDir\(\) in .+` `os\.MkdirTemp\(\) could be replaced by t\.TempDir\(\) in .+`
104+
MkdirTemp("", "") // want `os\.MkdirTemp\(\) could be replaced by t\.TempDir\(\) in .+`
105105
})
106106
}
107107
}

testdata/src/osmkdirtemp/nottestfiles/nottestfiles_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func FunctionFuncLit_ExprStmt(t *testing.T) {
105105

106106
for _, test := range testCases {
107107
t.Run(test.desc, func(t *testing.T) {
108-
os.MkdirTemp("", "") // want `os\.MkdirTemp\(\) could be replaced by t\.TempDir\(\) in .+` `os\.MkdirTemp\(\) could be replaced by t\.TempDir\(\) in .+`
108+
os.MkdirTemp("", "") // want `os\.MkdirTemp\(\) could be replaced by t\.TempDir\(\) in .+`
109109
})
110110
}
111111
}

testdata/src/ossetenv/basic/basic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func Test_FuncLit_ExprStmt(t *testing.T) {
100100

101101
for _, test := range testCases {
102102
t.Run(test.desc, func(t *testing.T) {
103-
os.Setenv("", "") // want `os\.Setenv\(\) could be replaced by t\.Setenv\(\) in .+` `os\.Setenv\(\) could be replaced by t\.Setenv\(\) in .+`
103+
os.Setenv("", "") // want `os\.Setenv\(\) could be replaced by t\.Setenv\(\) in .+`
104104
})
105105
}
106106
}

testdata/src/ossetenv/dot/dot_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func Test_FuncLit_ExprStmt(t *testing.T) {
100100

101101
for _, test := range testCases {
102102
t.Run(test.desc, func(t *testing.T) {
103-
Setenv("", "") // want `os\.Setenv\(\) could be replaced by t\.Setenv\(\) in .+` `os\.Setenv\(\) could be replaced by t\.Setenv\(\) in .+`
103+
Setenv("", "") // want `os\.Setenv\(\) could be replaced by t\.Setenv\(\) in .+`
104104
})
105105
}
106106
}

testdata/src/ossetenv/nottestfiles/nottestfiles_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func FunctionFuncLit_ExprStmt(t *testing.T) {
104104

105105
for _, test := range testCases {
106106
t.Run(test.desc, func(t *testing.T) {
107-
os.Setenv("", "") // want `os\.Setenv\(\) could be replaced by t\.Setenv\(\) in .+` `os\.Setenv\(\) could be replaced by t\.Setenv\(\) in .+`
107+
os.Setenv("", "") // want `os\.Setenv\(\) could be replaced by t\.Setenv\(\) in .+`
108108
})
109109
}
110110
}

testdata/src/ostempdir/basic/basic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func Test_FuncLit_ExprStmt(t *testing.T) {
100100

101101
for _, test := range testCases {
102102
t.Run(test.desc, func(t *testing.T) {
103-
os.TempDir() // want `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+` `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+`
103+
os.TempDir() // want `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+`
104104
})
105105
}
106106
}

testdata/src/ostempdir/dot/dot_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func Test_FuncLit_ExprStmt(t *testing.T) {
100100

101101
for _, test := range testCases {
102102
t.Run(test.desc, func(t *testing.T) {
103-
TempDir() // want `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+` `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+`
103+
TempDir() // want `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+`
104104
})
105105
}
106106
}

testdata/src/ostempdir/nottestfiles/nottestfiles_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func FunctionFuncLit_ExprStmt(t *testing.T) {
104104

105105
for _, test := range testCases {
106106
t.Run(test.desc, func(t *testing.T) {
107-
os.TempDir() // want `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+` `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+`
107+
os.TempDir() // want `os\.TempDir\(\) could be replaced by t\.TempDir\(\) in .+`
108108
})
109109
}
110110
}

usetesting.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,11 @@ func (a *analyzer) run(pass *analysis.Pass) (any, error) {
102102

103103
nodeFilter := []ast.Node{
104104
(*ast.FuncDecl)(nil),
105-
(*ast.FuncLit)(nil),
106105
}
107106

108107
insp.Preorder(nodeFilter, func(node ast.Node) {
109-
switch fn := node.(type) {
110-
case *ast.FuncDecl:
108+
if fn, ok := node.(*ast.FuncDecl); ok {
111109
a.checkFunc(pass, fn.Type, fn.Body, fn.Name.Name)
112-
113-
case *ast.FuncLit:
114-
a.checkFunc(pass, fn.Type, fn.Body, "anonymous function")
115110
}
116111
})
117112

0 commit comments

Comments
 (0)