mirror of
https://github.com/kevin-DL/revel-cmd.git
synced 2026-01-19 13:45:19 +00:00
Lint fixes
This commit is contained in:
@@ -2,9 +2,10 @@ package parser
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
"github.com/revel/cmd/utils"
|
||||
"github.com/revel/cmd/model"
|
||||
"go/token"
|
||||
|
||||
"github.com/revel/cmd/model"
|
||||
"github.com/revel/cmd/utils"
|
||||
)
|
||||
|
||||
// If this Decl is a struct type definition, it is summarized and added to specs.
|
||||
@@ -91,7 +92,7 @@ func appendStruct(fileName string, specs []*model.TypeInfo, pkgImportPath string
|
||||
|
||||
// If decl is a Method declaration, it is summarized and added to the array
|
||||
// underneath its receiver type.
|
||||
// e.g. "Login" => {MethodSpec, MethodSpec, ..}
|
||||
// e.g. "Login" => {MethodSpec, MethodSpec, ..}.
|
||||
func appendAction(fset *token.FileSet, mm methodMap, decl ast.Decl, pkgImportPath, pkgName string, imports map[string]string) {
|
||||
// Func declaration?
|
||||
funcDecl, ok := decl.(*ast.FuncDecl)
|
||||
@@ -194,7 +195,7 @@ func appendAction(fset *token.FileSet, mm methodMap, decl ast.Decl, pkgImportPat
|
||||
})
|
||||
|
||||
var recvTypeName string
|
||||
var recvType = funcDecl.Recv.List[0].Type
|
||||
recvType := funcDecl.Recv.List[0].Type
|
||||
if recvStarType, ok := recvType.(*ast.StarExpr); ok {
|
||||
recvTypeName = recvStarType.X.(*ast.Ident).Name
|
||||
} else {
|
||||
@@ -204,7 +205,7 @@ func appendAction(fset *token.FileSet, mm methodMap, decl ast.Decl, pkgImportPat
|
||||
mm[recvTypeName] = append(mm[recvTypeName], method)
|
||||
}
|
||||
|
||||
// Combine the 2 source info models into one
|
||||
// Combine the 2 source info models into one.
|
||||
func appendSourceInfo(srcInfo1, srcInfo2 *model.SourceInfo) *model.SourceInfo {
|
||||
if srcInfo1 == nil {
|
||||
return srcInfo2
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package parser
|
||||
|
||||
import (
|
||||
"github.com/revel/cmd/utils"
|
||||
"go/ast"
|
||||
"go/build"
|
||||
"go/token"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/revel/cmd/utils"
|
||||
)
|
||||
|
||||
// Add imports to the map from the source dir
|
||||
// Add imports to the map from the source dir.
|
||||
func addImports(imports map[string]string, decl ast.Decl, srcDir string) {
|
||||
genDecl, ok := decl.(*ast.GenDecl)
|
||||
if !ok {
|
||||
@@ -42,7 +43,6 @@ func addImports(imports map[string]string, decl ast.Decl, srcDir string) {
|
||||
// 2. Exempt the standard library; their directories always match the package name.
|
||||
// 3. Can use build.FindOnly and then use parser.ParseDir with mode PackageClauseOnly
|
||||
if pkgAlias == "" {
|
||||
|
||||
utils.Logger.Debug("Reading from build", "path", fullPath, "srcPath", srcDir, "gopath", build.Default.GOPATH)
|
||||
pkg, err := build.Import(fullPath, srcDir, 0)
|
||||
if err != nil {
|
||||
@@ -63,7 +63,7 @@ func addImports(imports map[string]string, decl ast.Decl, srcDir string) {
|
||||
}
|
||||
|
||||
// Returns a valid import string from the path
|
||||
// using the build.Defaul.GOPATH to determine the root
|
||||
// using the build.Defaul.GOPATH to determine the root.
|
||||
func importPathFromPath(root, basePath string) string {
|
||||
vendorTest := filepath.Join(basePath, "vendor")
|
||||
if len(root) > len(vendorTest) && root[:len(vendorTest)] == vendorTest {
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"github.com/revel/cmd/utils"
|
||||
)
|
||||
|
||||
// A container used to support the reflection package
|
||||
// A container used to support the reflection package.
|
||||
type processContainer struct {
|
||||
root, rootImportPath string // The paths
|
||||
paths *model.RevelContainer // The Revel paths
|
||||
@@ -54,7 +54,7 @@ func ProcessSource(paths *model.RevelContainer) (_ *model.SourceInfo, compileErr
|
||||
return pc.srcInfo, compileError
|
||||
}
|
||||
|
||||
// Called during the "walk process"
|
||||
// Called during the "walk process".
|
||||
func (pc *processContainer) processPath(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
utils.Logger.Error("Error scanning app source:", "error", err)
|
||||
@@ -84,7 +84,7 @@ func (pc *processContainer) processPath(path string, info os.FileInfo, err error
|
||||
|
||||
if err != nil {
|
||||
if errList, ok := err.(scanner.ErrorList); ok {
|
||||
var pos = errList[0].Pos
|
||||
pos := errList[0].Pos
|
||||
newError := &utils.SourceError{
|
||||
SourceType: ".go source",
|
||||
Title: "Go Compilation Error",
|
||||
@@ -114,7 +114,7 @@ func (pc *processContainer) processPath(path string, info os.FileInfo, err error
|
||||
// These cannot be included in source code that is not generated specifically as a test
|
||||
for i := range pkgs {
|
||||
if len(i) > 6 {
|
||||
if string(i[len(i)-5:]) == "_test" {
|
||||
if i[len(i)-5:] == "_test" {
|
||||
delete(pkgs, i)
|
||||
}
|
||||
}
|
||||
@@ -146,7 +146,7 @@ func (pc *processContainer) processPath(path string, info os.FileInfo, err error
|
||||
return nil
|
||||
}
|
||||
|
||||
// Process a single package within a file
|
||||
// Process a single package within a file.
|
||||
func processPackage(fset *token.FileSet, pkgImportPath, pkgPath string, pkg *ast.Package) *model.SourceInfo {
|
||||
var (
|
||||
structSpecs []*model.TypeInfo
|
||||
|
||||
@@ -67,7 +67,7 @@ var expectedValidationKeys = []map[int]string{
|
||||
},
|
||||
}
|
||||
|
||||
// This tests the recording of line number to validation key of the preceeding
|
||||
// This tests the recording of line number to validation key of the preceding
|
||||
// example source.
|
||||
func TestGetValidationKeys(t *testing.T) {
|
||||
fset := token.NewFileSet()
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package parser
|
||||
|
||||
import (
|
||||
"github.com/revel/cmd/model"
|
||||
"github.com/revel/cmd/utils"
|
||||
"go/ast"
|
||||
"go/token"
|
||||
|
||||
"github.com/revel/cmd/model"
|
||||
"github.com/revel/cmd/utils"
|
||||
)
|
||||
|
||||
// Scan app source code for calls to X.Y(), where X is of type *Validation.
|
||||
|
||||
Reference in New Issue
Block a user