@@ -69,52 +69,3 @@ func doNotCallTFailNowInsideGoroutine(m dsl.Matcher) {
69
69
Where (m ["t" ].Type .Implements ("testing.TB" ) && m ["fail" ].Text .Matches ("^(FailNow|Fatal|Fatalf)$" )).
70
70
Report ("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)" )
71
71
}
72
-
73
- // InTx checks to ensure the database used inside the transaction closure is the transaction
74
- // database, and not the original database that creates the tx.
75
- func InTx (m dsl.Matcher ) {
76
- m .Import ("github.com/coder/coder/coderd/database" )
77
-
78
- // ':=' and '=' are different matches. Really...
79
- m .Match (`
80
- $x.InTx(func($y database.Store) error {
81
- $*_
82
- $*_ := $x.$f($*_)
83
- $*_
84
- })
85
- ` , `
86
- $x.InTx(func($y database.Store) error {
87
- $*_
88
- $*_ = $x.$f($*_)
89
- $*_
90
- })
91
- ` ).Where (m ["x" ].Text != m ["y" ].Text && m ["x" ].Type .Implements ("database.Store" )).
92
- At (m ["f" ]).
93
- Report ("Do not use the database directly within the InTx closure. Use '$y' instead of '$x'." )
94
-
95
- // When using a tx closure, ensure that if you pass the db to another
96
- // function inside the closure, it is the tx.
97
- // This will miss more complex cases such as passing the db as apart
98
- // of another struct.
99
- m .Match (
100
- `
101
- $x.InTx(func($y database.Store) error {
102
- $*_
103
- $*_ := $f($*_, $x, $*_)
104
- $*_
105
- })
106
- ` , `
107
- $x.InTx(func($y database.Store) error {
108
- $*_
109
- $*_ = $f($*_, $x, $*_)
110
- $*_
111
- })
112
- ` , `
113
- $x.InTx(func($y database.Store) error {
114
- $*_
115
- $f($*_, $x, $*_)
116
- $*_
117
- })
118
- ` ).Where (m ["x" ].Text != m ["y" ].Text && m ["x" ].Type .Implements ("database.Store" )).
119
- At (m ["f" ]).Report ("Pass the tx database into the '$f' function inside the closure. Use '$y' over $x'" )
120
- }
0 commit comments