Skip to content

Commit fe31f5d

Browse files
committed
use 'Is' instead of 'Implements'
1 parent 20f76ba commit fe31f5d

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

scripts/rules.go

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -143,26 +143,22 @@ func publishInTransaction(m dsl.Matcher) {
143143

144144
// Match direct calls to the Publish method of a pubsub instance inside InTx
145145
m.Match(`
146-
$db.InTx(func($tx $dbType) $retType {
146+
$x.InTx(func($y) error {
147147
$*_
148-
$ps.Publish($*args)
148+
$_ = $ps.Publish($evt, $msg)
149149
$*_
150-
}, $*txopts)
151-
`).
152-
Where(m["ps"].Type.Implements("pubsub.Pubsub") ||
153-
m["ps"].Text.Matches(`\w+\.pubsub`) ||
154-
m["ps"].Text.Matches(`pubsub\.\w+`)).
155-
Report("Avoid calling Publish inside database transactions as this may lead to connection deadlocks. Move the Publish call outside the transaction.")
156-
157-
// Also catch publish calls on nested fields like c.pubsub.Publish()
158-
m.Match(`
159-
$db.InTx(func($tx $dbType) $retType {
150+
}, $*_)
151+
`,
152+
// Without catching error return
153+
`
154+
$x.InTx(func($y) error {
160155
$*_
161-
$ps.$field.Publish($*args)
156+
$ps.Publish($evt, $msg)
162157
$*_
163-
}, $*txopts)
158+
}, $*_)
164159
`).
165-
Where(m["field"].Text == "pubsub").
160+
Where(m["ps"].Type.Is("pubsub.Pubsub")).
161+
At(m["ps"]).
166162
Report("Avoid calling Publish inside database transactions as this may lead to connection deadlocks. Move the Publish call outside the transaction.")
167163
}
168164

0 commit comments

Comments
 (0)