Skip to content

Commit

Permalink
ruleguard: move IsNil check above strings.Contains
Browse files Browse the repository at this point in the history
  • Loading branch information
quasilyte committed Jan 2, 2022
1 parent 4a96fd7 commit 33b89ea
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ruleguard/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,6 @@ func (rr *rulesRunner) renderMessage(msg string, m matchData, truncate bool) str

for _, c := range capture {
n := c.Node
key := "$" + c.Name
if !strings.Contains(msg, key) {
continue
}
// Some captured nodes are typed, but nil.
// We can't really get their text, so skip them here.
// For example, pattern `func $_() $results { $*_ }` may
Expand All @@ -399,6 +395,10 @@ func (rr *rulesRunner) renderMessage(msg string, m matchData, truncate bool) str
if reflect.ValueOf(n).IsNil() {
continue
}
key := "$" + c.Name
if !strings.Contains(msg, key) {
continue
}
buf.Reset()
buf.Write(rr.nodeText(n))
replacement := buf.String()
Expand Down

0 comments on commit 33b89ea

Please sign in to comment.