-
Notifications
You must be signed in to change notification settings - Fork 2
/
receiver.go
47 lines (36 loc) · 1.01 KB
/
receiver.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package varnamelen
import (
"go/ast"
"golang.org/x/tools/go/analysis"
)
// receiver represents a declared method receiver.
type receiver struct {
// name is the name of the receiver.
name string
// typ is the type of the receiver.
typ string
// field is the declaration of the receiver.
field *ast.Field
}
// checkReceivers applies the analysis to method receivers in receiverToDist, according to cfg.
func checkReceivers(pass *analysis.Pass, receiverToDist map[receiver]int, cfg configuration) {
for recv, dist := range receiverToDist {
if cfg.ignoreNames.contains(recv.name) {
continue
}
if cfg.ignoreDecls.matchReceiver(recv) {
continue
}
if checkNameAndDistance(recv.name, dist, cfg) {
continue
}
pass.Reportf(recv.field.Pos(), "method receiver name '%s' is too short for the scope of its usage", recv.name)
}
}
// match returns whether r matches decl.
func (r receiver) match(decl identDeclaration) bool {
if r.name != decl.name {
return false
}
return decl.matchType(r.typ)
}