Skip to content

Commit 33b89ea

Browse files
committed
ruleguard: move IsNil check above strings.Contains
1 parent 4a96fd7 commit 33b89ea

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ruleguard/runner.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,6 @@ func (rr *rulesRunner) renderMessage(msg string, m matchData, truncate bool) str
387387

388388
for _, c := range capture {
389389
n := c.Node
390-
key := "$" + c.Name
391-
if !strings.Contains(msg, key) {
392-
continue
393-
}
394390
// Some captured nodes are typed, but nil.
395391
// We can't really get their text, so skip them here.
396392
// For example, pattern `func $_() $results { $*_ }` may
@@ -399,6 +395,10 @@ func (rr *rulesRunner) renderMessage(msg string, m matchData, truncate bool) str
399395
if reflect.ValueOf(n).IsNil() {
400396
continue
401397
}
398+
key := "$" + c.Name
399+
if !strings.Contains(msg, key) {
400+
continue
401+
}
402402
buf.Reset()
403403
buf.Write(rr.nodeText(n))
404404
replacement := buf.String()

0 commit comments

Comments
 (0)