Skip to content

Commit

Permalink
perfguard/_rules: add constErrorNew opt rule (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
quasilyte authored Jan 10, 2022
1 parent 5a95f50 commit fb88f2c
Show file tree
Hide file tree
Showing 3 changed files with 950 additions and 922 deletions.
8 changes: 8 additions & 0 deletions perfguard/_rules/opt_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ func rangeValueCopy(m dsl.Matcher) {
Where(m["v"].Type.Size > 128).
Report(`every iteration copies a large object into $v`)
}

//doc:summary Detects errors.New that can be allocated exactly once
//doc:tags o1 score3
func constErrorNew(m dsl.Matcher) {
m.Match(`errors.New($x)`).
Where(m["x"].Const).
Report(`errors with const message can be a global var, allocated only once`)
}
18 changes: 18 additions & 0 deletions perfguard/rulesdata/opt_rules.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fb88f2c

Please sign in to comment.