-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreturn.go
47 lines (36 loc) · 1.02 KB
/
return.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"
)
// namedReturn represents a declared named return value.
type namedReturn struct {
// name is the name of the return value.
name string
// typ is the type of the return value.
typ string
// field is the declaration of the return value.
field *ast.Field
}
// checkReceivers applies the analysis to named return values in returnToDist, according to cfg.
func checkReturns(pass *analysis.Pass, returnToDist map[namedReturn]int, cfg configuration) {
for ret, dist := range returnToDist {
if cfg.ignoreNames.contains(ret.name) {
continue
}
if cfg.ignoreDecls.matchNamedReturn(ret) {
continue
}
if checkNameAndDistance(ret.name, dist, cfg) {
continue
}
pass.Reportf(ret.field.Pos(), "return value name '%s' is too short for the scope of its usage", ret.name)
}
}
// match returns whether r matches decl.
func (r namedReturn) match(decl identDeclaration) bool {
if r.name != decl.name {
return false
}
return decl.matchType(r.typ)
}