blob: 8f2f741ce6f7c2ed0aad99683a8da4a7dbf60435 (
plain) (
blame)
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
|
package main
import (
"go/ast"
"strings"
"golang.org/x/tools/go/analysis"
)
func isQueryFunc(node *ast.FuncDecl) bool {
return strings.HasSuffix(node.Name.Name, "Query") && !strings.HasPrefix(node.Name.Name, "Test")
}
func checkQueryFunc(pass *analysis.Pass, node *ast.FuncDecl) {
if node.Type.Results.NumFields() != 3 {
pass.Reportf(node.Pos(), "query function must have 3 return values")
} else {
if !isIdent(node.Type.Results.List[1].Type, "int") {
pass.Reportf(node.Pos(), "query function must return an int code as the second return value")
}
if !isIdent(node.Type.Results.List[2].Type, "error") {
pass.Reportf(node.Pos(), "query function must return an error as the third return value")
}
}
}
|