summaryrefslogtreecommitdiff
path: root/cmd/cvet/check_query.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2023-10-24 07:34:00 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2023-10-24 07:34:00 +0200
commit435397de49adc9740bc67416166aba4d0be8ae2a (patch)
tree1642dccae517840f3256f35e29e8d7d1802f700f /cmd/cvet/check_query.go
parent18476c6cba2d5d2bb3ecf3ad136dacbf41d0360e (diff)
feat: Add cmds
Diffstat (limited to 'cmd/cvet/check_query.go')
-rw-r--r--cmd/cvet/check_query.go25
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")
+ }
+ }
+}