diff options
Diffstat (limited to 'cmd/cvet/check_query.go')
| -rw-r--r-- | cmd/cvet/check_query.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/cmd/cvet/check_query.go b/cmd/cvet/check_query.go new file mode 100644 index 0000000..bde3b9f --- /dev/null +++ b/cmd/cvet/check_query.go @@ -0,0 +1,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") +} + +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") + } + } +} |
