Added check to ignore functions which have no body (external functions)

Added missing sort package
This commit is contained in:
NotZippy
2018-01-30 09:23:21 -08:00
parent 0583fe7d32
commit 91f43bf94c
2 changed files with 6 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ import (
"strings"
"text/template"
"time"
"sort"
"github.com/revel/revel"
)

View File

@@ -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}
}