forked from go-critic/go-critic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules.go
31 lines (25 loc) · 769 Bytes
/
rules.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//go:build ignore
// +build ignore
package gorules
import "github.com/quasilyte/go-ruleguard/dsl"
func errorUnderlying(m dsl.Matcher) {
m.Match(`type $x error`).
Report(`error as an underlying type is probably a mistake`).
Suggest(`type $x struct { error }`)
}
func sprintfConcat(m dsl.Matcher) {
m.Match(`fmt.Sprintf("%s%s", $a, $b)`).
Where(m["a"].Type.Is(`string`) && m["b"].Type.Is(`string`)).
Suggest(`$a+$b`)
}
//doc:tags test
func stackedIf(m dsl.Matcher) {
m.Match(`if $*_ { if $*_ { $*_ } }`).
Report(`may be simplified to one if`)
}
//doc:tags style
func dynamicFmtString(m dsl.Matcher) {
m.Match(`fmt.Errorf($f($*args))`).
Suggest("errors.New($f($args))").
Report(`use errors.New($f($args)) or fmt.Errorf("%s", $f($args)) instead`)
}