mirror of
https://github.com/kevin-DL/revel-cmd.git
synced 2026-01-11 18:54:31 +00:00
More linting
This commit is contained in:
@@ -28,6 +28,11 @@ const (
|
||||
VERSION
|
||||
)
|
||||
|
||||
const (
|
||||
ErrImportInvalid Error = "invalid import path, working dir is in GOPATH root"
|
||||
ErrUnableToImport Error = "unable to determine import path from"
|
||||
)
|
||||
|
||||
type (
|
||||
// The Revel command type.
|
||||
COMMAND int
|
||||
@@ -110,7 +115,7 @@ func (c *CommandConfig) UpdateImportPath() error {
|
||||
importPath = importPath[4:]
|
||||
} else if importPath == "src" {
|
||||
if c.Index != VERSION {
|
||||
return fmt.Errorf("invalid import path, working dir is in GOPATH root")
|
||||
return ErrImportInvalid
|
||||
}
|
||||
importPath = ""
|
||||
}
|
||||
@@ -122,7 +127,10 @@ func (c *CommandConfig) UpdateImportPath() error {
|
||||
|
||||
c.ImportPath = importPath
|
||||
// We need the source root determined at this point to check the setversions
|
||||
c.initAppFolder()
|
||||
if err := c.initAppFolder(); err != nil {
|
||||
utils.Logger.Error("Error initing app folder", "error", err)
|
||||
}
|
||||
|
||||
utils.Logger.Info("Returned import path", "path", importPath)
|
||||
if required && c.Index != NEW {
|
||||
if err := c.SetVersions(); err != nil {
|
||||
@@ -138,7 +146,7 @@ func (c *CommandConfig) UpdateImportPath() error {
|
||||
return nil
|
||||
}
|
||||
if len(importPath) == 0 {
|
||||
return fmt.Errorf("unable to determine import path from : %s", importPath)
|
||||
return fmt.Errorf("%w: %s", ErrUnableToImport, importPath)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@@ -13,6 +12,24 @@ import (
|
||||
"golang.org/x/tools/go/packages"
|
||||
)
|
||||
|
||||
// Error is used for constant errors.
|
||||
type Error string
|
||||
|
||||
// Error implements the error interface.
|
||||
func (e Error) Error() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
const (
|
||||
ErrNoApp Error = "no app found at path"
|
||||
ErrNoConfig Error = "no config found at path"
|
||||
ErrNotFound Error = "not found"
|
||||
ErrMissingCert Error = "no http.sslcert provided"
|
||||
ErrMissingKey Error = "no http.sslkey provided"
|
||||
ErrNoFiles Error = "no files found in import path"
|
||||
ErrNoPackages Error = "no packages found for import"
|
||||
)
|
||||
|
||||
type (
|
||||
// The container object for describing all Revels variables.
|
||||
RevelContainer struct {
|
||||
@@ -123,10 +140,10 @@ func NewRevelPaths(mode, importPath, appSrcPath string, callback RevelCallback)
|
||||
|
||||
// Sanity check , ensure app and conf paths exist
|
||||
if !utils.DirExists(rp.AppPath) {
|
||||
return rp, fmt.Errorf("no application found at path %s", rp.AppPath)
|
||||
return rp, fmt.Errorf("%w: %s", ErrNoApp, rp.AppPath)
|
||||
}
|
||||
if !utils.DirExists(filepath.Join(rp.BasePath, "conf")) {
|
||||
return rp, fmt.Errorf("no configuration found at path %s", filepath.Join(rp.BasePath, "conf"))
|
||||
return rp, fmt.Errorf("%w: %s", ErrNoConfig, filepath.Join(rp.BasePath, "conf"))
|
||||
}
|
||||
|
||||
rp.ViewsPath = filepath.Join(rp.AppPath, "views")
|
||||
@@ -150,7 +167,7 @@ func NewRevelPaths(mode, importPath, appSrcPath string, callback RevelCallback)
|
||||
|
||||
rp.Config, err = config.LoadContext("app.conf", rp.ConfPaths)
|
||||
if err != nil {
|
||||
return rp, fmt.Errorf("unable to load configuration file %s", err)
|
||||
return rp, fmt.Errorf("unable to load configuration file %w", err)
|
||||
}
|
||||
|
||||
// Ensure that the selected runmode appears in app.conf.
|
||||
@@ -159,7 +176,7 @@ func NewRevelPaths(mode, importPath, appSrcPath string, callback RevelCallback)
|
||||
mode = config.DefaultSection
|
||||
}
|
||||
if !rp.Config.HasSection(mode) {
|
||||
return rp, fmt.Errorf("app.conf: No mode found: %s %s", "run-mode", mode)
|
||||
return rp, fmt.Errorf("app.conf: %w %s %s", ErrNotFound, "run-mode", mode)
|
||||
}
|
||||
rp.Config.SetSection(mode)
|
||||
|
||||
@@ -172,13 +189,14 @@ func NewRevelPaths(mode, importPath, appSrcPath string, callback RevelCallback)
|
||||
rp.HTTPSslKey = rp.Config.StringDefault("http.sslkey", "")
|
||||
if rp.HTTPSsl {
|
||||
if rp.HTTPSslCert == "" {
|
||||
return rp, errors.New("no http.sslcert provided")
|
||||
return rp, ErrMissingCert
|
||||
}
|
||||
|
||||
if rp.HTTPSslKey == "" {
|
||||
return rp, errors.New("no http.sslkey provided")
|
||||
return rp, ErrMissingKey
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
rp.AppName = rp.Config.StringDefault("app.name", "(not set)")
|
||||
rp.AppRoot = rp.Config.StringDefault("app.root", "")
|
||||
rp.CookiePrefix = rp.Config.StringDefault("cookie.prefix", "REVEL")
|
||||
@@ -201,7 +219,7 @@ func NewRevelPaths(mode, importPath, appSrcPath string, callback RevelCallback)
|
||||
func (rp *RevelContainer) LoadMimeConfig() (err error) {
|
||||
rp.MimeConfig, err = config.LoadContext("mime-types.conf", rp.ConfPaths)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to load mime type config: %s %s", "error", err)
|
||||
return fmt.Errorf("failed to load mime type config: %s %w", "error", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -226,10 +244,14 @@ func (rp *RevelContainer) loadModules(callback RevelCallback) (err error) {
|
||||
modulePath, err := rp.ResolveImportPath(moduleImportPath)
|
||||
if err != nil {
|
||||
utils.Logger.Info("Missing module ", "module_import_path", moduleImportPath, "error", err)
|
||||
callback.PackageResolver(moduleImportPath)
|
||||
|
||||
if err := callback.PackageResolver(moduleImportPath); err != nil {
|
||||
return fmt.Errorf("failed to resolve package %w", err)
|
||||
}
|
||||
|
||||
modulePath, err = rp.ResolveImportPath(moduleImportPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to load module. Import of path failed %s:%s %s:%s ", "modulePath", moduleImportPath, "error", err)
|
||||
return fmt.Errorf("failed to load module. Import of path failed %s:%s %s:%w ", "modulePath", moduleImportPath, "error", err)
|
||||
}
|
||||
}
|
||||
// Drop anything between module.???.<name of module>
|
||||
@@ -281,7 +303,7 @@ func (rp *RevelContainer) ResolveImportPath(importPath string) (string, error) {
|
||||
|
||||
pkgs, err := packages.Load(config, importPath)
|
||||
if len(pkgs) == 0 {
|
||||
return "", errors.New("No packages found for import " + importPath + " using app path " + rp.AppPath)
|
||||
return "", fmt.Errorf("%w %s using app path %s", ErrNoPackages, importPath, rp.AppPath)
|
||||
}
|
||||
// modPkg, err := build.Import(importPath, rp.AppPath, build.FindOnly)
|
||||
if err != nil {
|
||||
@@ -290,5 +312,5 @@ func (rp *RevelContainer) ResolveImportPath(importPath string) (string, error) {
|
||||
if len(pkgs[0].GoFiles) > 0 {
|
||||
return filepath.Dir(pkgs[0].GoFiles[0]), nil
|
||||
}
|
||||
return pkgs[0].PkgPath, errors.New("No files found in import path " + importPath)
|
||||
return pkgs[0].PkgPath, fmt.Errorf("%w: %s", ErrNoFiles, importPath)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func NewTypeExprFromData(expr, pkgName string, pkgIndex int, valid bool) TypeExp
|
||||
|
||||
// NewTypeExpr returns the syntactic expression for referencing this type in Go.
|
||||
func NewTypeExprFromAst(pkgName string, expr ast.Expr) TypeExpr {
|
||||
error := ""
|
||||
err := ""
|
||||
switch t := expr.(type) {
|
||||
case *ast.Ident:
|
||||
if IsBuiltinType(t.Name) {
|
||||
@@ -41,14 +41,14 @@ func NewTypeExprFromAst(pkgName string, expr ast.Expr) TypeExpr {
|
||||
e := NewTypeExprFromAst(pkgName, t.Value)
|
||||
return NewTypeExprFromData("map["+identKey.Name+"]"+e.Expr, e.PkgName, e.pkgIndex+len("map["+identKey.Name+"]"), e.Valid)
|
||||
}
|
||||
error = fmt.Sprintf("Failed to generate name for Map field :%v. Make sure the field name is valid.", t.Key)
|
||||
err = fmt.Sprintf("Failed to generate name for Map field :%v. Make sure the field name is valid.", t.Key)
|
||||
case *ast.Ellipsis:
|
||||
e := NewTypeExprFromAst(pkgName, t.Elt)
|
||||
return NewTypeExprFromData("[]"+e.Expr, e.PkgName, e.pkgIndex+2, e.Valid)
|
||||
default:
|
||||
error = fmt.Sprintf("Failed to generate name for field: %v Package: %v. Make sure the field name is valid.", expr, pkgName)
|
||||
err = fmt.Sprintf("Failed to generate name for field: %v Package: %v. Make sure the field name is valid.", expr, pkgName)
|
||||
}
|
||||
return NewTypeExprFromData(error, "", 0, false)
|
||||
return NewTypeExprFromData(err, "", 0, false)
|
||||
}
|
||||
|
||||
// TypeName returns the fully-qualified type name for this expression.
|
||||
@@ -61,7 +61,7 @@ func (e TypeExpr) TypeName(pkgOverride string) string {
|
||||
return e.Expr[:e.pkgIndex] + pkgName + "." + e.Expr[e.pkgIndex:]
|
||||
}
|
||||
|
||||
var builtInTypes = map[string]struct{}{
|
||||
var builtInTypes = map[string]struct{}{ //nolint:gochecknoglobals
|
||||
"bool": {},
|
||||
"byte": {},
|
||||
"complex128": {},
|
||||
|
||||
Reference in New Issue
Block a user