From 91f43bf94cfb51c8e005cd03e4ed91e25a582ff9 Mon Sep 17 00:00:00 2001 From: NotZippy Date: Tue, 30 Jan 2018 09:23:21 -0800 Subject: [PATCH] Added check to ignore functions which have no body (external functions) Added missing sort package --- harness/build.go | 1 + harness/reflect.go | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/harness/build.go b/harness/build.go index 4773560..295c1ea 100644 --- a/harness/build.go +++ b/harness/build.go @@ -17,6 +17,7 @@ import ( "strings" "text/template" "time" + "sort" "github.com/revel/revel" ) diff --git a/harness/reflect.go b/harness/reflect.go index 2e561cf..ae7f43f 100644 --- a/harness/reflect.go +++ b/harness/reflect.go @@ -20,6 +20,7 @@ import ( "unicode" "github.com/revel/revel" + "log" ) // SourceInfo is the top-level struct containing all extracted information @@ -222,8 +223,8 @@ func processPackage(fset *token.FileSet, pkgImportPath, pkgPath string, pkg *ast ) // For each source file in the package... + log.Println("Exaiming files in path", pkgPath) for _, file := range pkg.Files { - // Imports maps the package key to the full import path. // e.g. import "sample/app/models" => "models": "sample/app/models" imports := map[string]string{} @@ -240,8 +241,8 @@ func processPackage(fset *token.FileSet, pkgImportPath, pkgPath string, pkg *ast structSpecs = appendStruct(structSpecs, pkgImportPath, pkg, decl, imports, fset) } - // If this is a func... - if funcDecl, ok := decl.(*ast.FuncDecl); ok { + // If this is a func... (ignore nil for external (non-Go) function) + if funcDecl, ok := decl.(*ast.FuncDecl); ok && funcDecl.Body != nil { // Scan it for validation calls lineKeys := getValidationKeys(fset, funcDecl, imports) if len(lineKeys) > 0 { @@ -794,7 +795,7 @@ func NewTypeExpr(pkgName string, expr ast.Expr) TypeExpr { e := NewTypeExpr(pkgName, t.Elt) return TypeExpr{"[]" + e.Expr, e.PkgName, e.pkgIndex + 2, e.Valid} default: - revel.RevelLog.Error("Failed to generate name for field. Make sure the field name is valid.") + revel.RevelLog.Error("Failed to generate name for field. Make sure the field name is valid.", "package", pkgName, "expresion",expr) } return TypeExpr{Valid: false} }