Skip to content

Commit 6e14ef4

Browse files
committed
feat: Add ruleguard for require.Eventually
1 parent 94c3020 commit 6e14ef4

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

scripts/rules.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ func doNotCallTFailNowInsideGoroutine(m dsl.Matcher) {
5959
Where(m["require"].Text == "require").
6060
Report("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)")
6161

62+
// require.Eventually runs the function in a goroutine.
63+
m.Match(`
64+
require.Eventually(t, func() bool {
65+
$*_
66+
$require.$_($*_)
67+
$*_
68+
}, $*_)`).
69+
At(m["require"]).
70+
Where(m["require"].Text == "require").
71+
Report("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)")
72+
6273
m.Match(`
6374
go func($*_){
6475
$*_
@@ -90,10 +101,10 @@ func InTx(m dsl.Matcher) {
90101
At(m["f"]).
91102
Report("Do not use the database directly within the InTx closure. Use '$y' instead of '$x'.")
92103

93-
//When using a tx closure, ensure that if you pass the db to another
94-
//function inside the closure, it is the tx.
95-
//This will miss more complex cases such as passing the db as apart
96-
//of another struct.
104+
// When using a tx closure, ensure that if you pass the db to another
105+
// function inside the closure, it is the tx.
106+
// This will miss more complex cases such as passing the db as apart
107+
// of another struct.
97108
m.Match(`
98109
$x.InTx(func($y database.Store) error {
99110
$*_

0 commit comments

Comments
 (0)