-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Hi there,
Great linter. Although I prefer to use it by pinning the variable inside the for loop, before calling t.Parallel() for test cases and the linter detects it as invalid. Maybe you could add a rule for such thing? There are a few cases I can think of:
Pinning the variable before t.Run
func Test(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
n int
}{
"zero": {n: 0},
"one": {n: 1},
}
for name, testCase := range testCases {
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()
t.Log(testCase.n)
})
}
}Pinning the variable inside t.Run before t.Parallel()
func Test(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
n int
}{
"zero": {n: 0},
"one": {n: 1},
}
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
testCase := testCase
t.Parallel()
t.Log(testCase.n)
})
}
}Pretty much pinning the variable between the for and the t.Parallel() should pass the linting, although some additional checks might be needed such as if the pinned variable has a different name etc.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels