From 3f131e3817d6a78854cff281e4725f02b410c1ad Mon Sep 17 00:00:00 2001 From: asoseil Date: Mon, 27 Nov 2017 00:01:08 +0100 Subject: [PATCH] lint --- realize/cli.go | 24 +++++++++++++++++------- realize/notify.go | 2 +- realize/projects.go | 36 ++++++++++++++++++------------------ realize/projects_test.go | 28 ++++++++++++++-------------- realize/style.go | 16 +++++++++++----- realize_test.go | 4 ++-- 6 files changed, 63 insertions(+), 47 deletions(-) diff --git a/realize/cli.go b/realize/cli.go index fdae684..4a64c60 100644 --- a/realize/cli.go +++ b/realize/cli.go @@ -2,8 +2,8 @@ package realize import ( "fmt" - "go/build" "github.com/fsnotify/fsnotify" + "go/build" "log" "os" "os/signal" @@ -14,17 +14,25 @@ import ( ) const ( - RPrefix = "realize" + // RPrefix tool name + RPrefix = "realize" + // RVersion current version RVersion = "2.0" - RExt = ".yaml" - RFile = RPrefix + RExt - RDir = "." + RPrefix - RExtWin = ".exe" + // RExt file extension + RExt = ".yaml" + // RFile config file name + RFile = RPrefix + RExt + // RDir config dir + RDir = "." + RPrefix + //RExtWin windows extension + RExtWin = ".exe" ) type ( + // LogWriter used for all log LogWriter struct{} + // Realize main struct Realize struct { Settings Settings `yaml:"settings" json:"settings"` Server Server `yaml:"server" json:"server"` @@ -38,6 +46,7 @@ type ( Reload Func `yaml:"-"` } + // Context is used as argument for func Context struct { Path string Project *Project @@ -46,6 +55,7 @@ type ( Event fsnotify.Event } + // Func is used instead realize func Func func(Context) ) @@ -67,7 +77,7 @@ func (r *Realize) Stop() { close(r.exit) } -// Run realize workflow +// Start realize workflow func (r *Realize) Start() { r.exit = make(chan os.Signal, 2) signal.Notify(r.exit, os.Interrupt, syscall.SIGTERM) diff --git a/realize/notify.go b/realize/notify.go index d5c97cd..01b254c 100644 --- a/realize/notify.go +++ b/realize/notify.go @@ -66,7 +66,7 @@ func PollingWatcher(interval time.Duration) FileWatcher { } } -// NewWatcher tries to use an fs-event watcher, and falls back to the poller if there is an error +// NewFileWatcher tries to use an fs-event watcher, and falls back to the poller if there is an error func NewFileWatcher(force bool, interval time.Duration) (FileWatcher, error) { if !force { if w, err := EventWatcher(); err == nil { diff --git a/realize/projects.go b/realize/projects.go index 8d3648b..d9deed2 100644 --- a/realize/projects.go +++ b/realize/projects.go @@ -87,18 +87,18 @@ type BufferOut struct { } // After stop watcher -func (p *Project) After(){ - if p.parent.After != nil{ - p.parent.After(Context{Project:p}) +func (p *Project) After() { + if p.parent.After != nil { + p.parent.After(Context{Project: p}) return } p.cmd(nil, "after", true) } // Before start watcher -func (p *Project) Before(){ - if p.parent.Before != nil{ - p.parent.Before(Context{Project:p}) +func (p *Project) Before() { + if p.parent.Before != nil { + p.parent.Before(Context{Project: p}) return } // setup go tools @@ -127,10 +127,10 @@ func (p *Project) Before(){ p.stamp("log", out, msg, "") } -// Error occurred +// Err occurred func (p *Project) Err(err error) { - if p.parent.Err != nil{ - p.parent.Err(Context{Project:p}) + if p.parent.Err != nil { + p.parent.Err(Context{Project: p}) return } if err != nil { @@ -142,8 +142,8 @@ func (p *Project) Err(err error) { // Change event message func (p *Project) Change(event fsnotify.Event) { - if p.parent.Change != nil{ - p.parent.Change(Context{Project:p,Event:event}) + if p.parent.Change != nil { + p.parent.Change(Context{Project: p, Event: event}) return } // file extension @@ -159,8 +159,8 @@ func (p *Project) Change(event fsnotify.Event) { // Reload launches the toolchain run, build, install func (p *Project) Reload(watcher FileWatcher, path string, stop <-chan bool) { - if p.parent.Reload != nil{ - p.parent.Reload(Context{Project:p,Watcher:watcher,Path:path,Stop:stop}) + if p.parent.Reload != nil { + p.parent.Reload(Context{Project: p, Watcher: watcher, Path: path, Stop: stop}) return } var done bool @@ -183,9 +183,9 @@ func (p *Project) Reload(watcher FileWatcher, path string, stop <-chan bool) { return } // Go supported tools - if len(path) > 0{ + if len(path) > 0 { fi, err := os.Stat(path) - if err != nil{ + if err != nil { p.Err(err) } p.tools(stop, path, fi) @@ -340,7 +340,7 @@ L: // Validate a file path func (p *Project) Validate(path string, fiche bool) bool { - if len(path) <= 0{ + if len(path) <= 0 { return false } // check if skip hidden @@ -414,7 +414,7 @@ func (p *Project) tools(stop <-chan bool, path string, fi os.FileInfo) { if tool.dir { result <- tool.Exec(path, stop) } - } else if !tool.dir{ + } else if !tool.dir { result <- tool.Exec(path, stop) } } @@ -483,7 +483,7 @@ func (p *Project) walk(path string, info os.FileInfo, err error) error { if p.Validate(path, true) { result := p.watcher.Walk(path, p.init) if result != "" { - p.tools(p.stop, path,info) + p.tools(p.stop, path, info) if info.IsDir() { // tools dir p.folders++ diff --git a/realize/projects_test.go b/realize/projects_test.go index 64e0a16..bd01947 100644 --- a/realize/projects_test.go +++ b/realize/projects_test.go @@ -1,12 +1,12 @@ package realize import ( - "testing" - "log" "bytes" - "strings" - "os" "errors" + "log" + "os" + "strings" + "testing" ) func TestProject_After(t *testing.T) { @@ -14,10 +14,10 @@ func TestProject_After(t *testing.T) { log.SetOutput(&buf) r := Realize{} input := "text" - r.After = func(context Context){ + r.After = func(context Context) { log.Println(input) } - r.Projects = append(r.Projects,Project{ + r.Projects = append(r.Projects, Project{ parent: &r, }) r.Projects[0].After() @@ -30,11 +30,11 @@ func TestProject_Before(t *testing.T) { var buf bytes.Buffer log.SetOutput(&buf) r := Realize{} - r.Projects = append(r.Projects,Project{ + r.Projects = append(r.Projects, Project{ parent: &r, }) input := "text" - r.Before = func(context Context){ + r.Before = func(context Context) { log.Println(input) } r.Projects[0].Before() @@ -43,15 +43,15 @@ func TestProject_Before(t *testing.T) { } r = Realize{} - r.Projects = append(r.Projects,Project{ + r.Projects = append(r.Projects, Project{ parent: &r, Environment: map[string]string{ input: input, }, }) r.Projects[0].Before() - if os.Getenv(input) != input{ - t.Error("Unexpected error expected", input, "instead",os.Getenv(input)) + if os.Getenv(input) != input { + t.Error("Unexpected error expected", input, "instead", os.Getenv(input)) } } @@ -59,11 +59,11 @@ func TestProject_Err(t *testing.T) { var buf bytes.Buffer log.SetOutput(&buf) r := Realize{} - r.Projects = append(r.Projects,Project{ + r.Projects = append(r.Projects, Project{ parent: &r, }) input := "text" - r.Err = func(context Context){ + r.Err = func(context Context) { log.Println(input) } r.Projects[0].Err(errors.New(input)) @@ -74,4 +74,4 @@ func TestProject_Err(t *testing.T) { func TestProject_Change(t *testing.T) { -} \ No newline at end of file +} diff --git a/realize/style.go b/realize/style.go index d90f643..c466f24 100644 --- a/realize/style.go +++ b/realize/style.go @@ -5,11 +5,17 @@ import ( ) var ( - Output = color.Output - Red = colorBase(color.FgHiRed) - Blue = colorBase(color.FgHiBlue) - Green = colorBase(color.FgHiGreen) - Yellow = colorBase(color.FgHiYellow) + //Output writer + Output = color.Output + // Red color + Red = colorBase(color.FgHiRed) + // Blue color + Blue = colorBase(color.FgHiBlue) + // Green color + Green = colorBase(color.FgHiGreen) + // Yellow color + Yellow = colorBase(color.FgHiYellow) + // Magenta color Magenta = colorBase(color.FgHiMagenta) ) diff --git a/realize_test.go b/realize_test.go index 553752f..981590b 100644 --- a/realize_test.go +++ b/realize_test.go @@ -2,11 +2,11 @@ package main import ( "bytes" + "errors" "github.com/tockins/realize/realize" "log" "strings" "testing" - "errors" ) var mockResponse interface{} @@ -138,4 +138,4 @@ func TestRealize_version(t *testing.T) { if !strings.Contains(buf.String(), realize.RVersion) { t.Error("Version expted", realize.RVersion) } -} \ No newline at end of file +}