From 97bc5ccd229b7b438262a84e3c42783b4d4a82af Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 8 Feb 2020 16:17:15 +0100 Subject: various cleanups suggested by golang-ci --- bug/interface.go | 6 +++--- bug/op_edit_comment.go | 9 +++------ commands/commands.go | 4 +--- go.mod | 1 - termui/msg_popup.go | 2 +- termui/show_bug.go | 54 ++++++++++++++++++++------------------------------ termui/termui.go | 2 -- 7 files changed, 29 insertions(+), 49 deletions(-) diff --git a/bug/interface.go b/bug/interface.go index 796ee569..5c8f2729 100644 --- a/bug/interface.go +++ b/bug/interface.go @@ -46,11 +46,11 @@ type Interface interface { } func bugFromInterface(bug Interface) *Bug { - switch bug.(type) { + switch bug := bug.(type) { case *Bug: - return bug.(*Bug) + return bug case *WithSnapshot: - return bug.(*WithSnapshot).Bug + return bug.Bug default: panic("missing type case") } diff --git a/bug/op_edit_comment.go b/bug/op_edit_comment.go index a37ce8f7..48020421 100644 --- a/bug/op_edit_comment.go +++ b/bug/op_edit_comment.go @@ -59,14 +59,11 @@ func (op *EditCommentOperation) Apply(snapshot *Snapshot) { UnixTime: timestamp.Timestamp(op.UnixTime), } - switch target.(type) { + switch target := target.(type) { case *CreateTimelineItem: - item := target.(*CreateTimelineItem) - item.Append(comment) - + target.Append(comment) case *AddCommentTimelineItem: - item := target.(*AddCommentTimelineItem) - item.Append(comment) + target.Append(comment) } // Updating the corresponding comment diff --git a/commands/commands.go b/commands/commands.go index a30c38a5..bd8cb14d 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -27,9 +27,7 @@ func runCommands(cmd *cobra.Command, args []string) error { cmd := queue[0] queue = queue[1:] allCmds = append(allCmds, cmd) - for _, c := range cmd.Commands() { - queue = append(queue, c) - } + queue = append(queue, cmd.Commands()...) } sort.Sort(commandSorterByName(allCmds)) diff --git a/go.mod b/go.mod index 3c127b7f..56e91373 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,6 @@ require ( github.com/gorilla/mux v1.7.3 github.com/hashicorp/golang-lru v0.5.4 // indirect github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428 - github.com/mattn/go-colorable v0.1.4 // indirect github.com/mattn/go-isatty v0.0.12 github.com/phayes/freeport v0.0.0-20171002181615-b8543db493a5 github.com/pkg/errors v0.9.1 diff --git a/termui/msg_popup.go b/termui/msg_popup.go index 236c16a2..d0e31634 100644 --- a/termui/msg_popup.go +++ b/termui/msg_popup.go @@ -63,7 +63,7 @@ func (ep *msgPopup) layout(g *gocui.Gui) error { v.Title = ep.title v.Clear() - fmt.Fprintf(v, wrapped) + _, _ = fmt.Fprint(v, wrapped) if _, err := g.SetCurrentView(msgPopupView); err != nil { return err diff --git a/termui/show_bug.go b/termui/show_bug.go index 6c7163ac..e483117a 100644 --- a/termui/show_bug.go +++ b/termui/show_bug.go @@ -238,18 +238,16 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error { // TODO: me might skip the rendering of blocks that are outside of the view // but to do that we need to rework how sb.mainSelectableView is maintained - switch op.(type) { + switch op := op.(type) { case *bug.CreateTimelineItem: - create := op.(*bug.CreateTimelineItem) - var content string var lines int - if create.MessageIsEmpty() { + if op.MessageIsEmpty() { content, lines = text.WrapLeftPadded(emptyMessagePlaceholder(), maxX-1, 4) } else { - content, lines = text.WrapLeftPadded(create.Message, maxX-1, 4) + content, lines = text.WrapLeftPadded(op.Message, maxX-1, 4) } v, err := sb.createOpView(g, viewName, x0, y0, maxX+1, lines, true) @@ -260,23 +258,21 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error { y0 += lines + 2 case *bug.AddCommentTimelineItem: - comment := op.(*bug.AddCommentTimelineItem) - edited := "" - if comment.Edited() { + if op.Edited() { edited = " (edited)" } var message string - if comment.MessageIsEmpty() { + if op.MessageIsEmpty() { message, _ = text.WrapLeftPadded(emptyMessagePlaceholder(), maxX-1, 4) } else { - message, _ = text.WrapLeftPadded(comment.Message, maxX-1, 4) + message, _ = text.WrapLeftPadded(op.Message, maxX-1, 4) } content := fmt.Sprintf("%s commented on %s%s\n\n%s", - colors.Magenta(comment.Author.DisplayName()), - comment.CreatedAt.Time().Format(timeLayout), + colors.Magenta(op.Author.DisplayName()), + op.CreatedAt.Time().Format(timeLayout), edited, message, ) @@ -290,12 +286,10 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error { y0 += lines + 2 case *bug.SetTitleTimelineItem: - setTitle := op.(*bug.SetTitleTimelineItem) - content := fmt.Sprintf("%s changed the title to %s on %s", - colors.Magenta(setTitle.Author.DisplayName()), - colors.Bold(setTitle.Title), - setTitle.UnixTime.Time().Format(timeLayout), + colors.Magenta(op.Author.DisplayName()), + colors.Bold(op.Title), + op.UnixTime.Time().Format(timeLayout), ) content, lines := text.Wrap(content, maxX) @@ -307,12 +301,10 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error { y0 += lines + 2 case *bug.SetStatusTimelineItem: - setStatus := op.(*bug.SetStatusTimelineItem) - content := fmt.Sprintf("%s %s the bug on %s", - colors.Magenta(setStatus.Author.DisplayName()), - colors.Bold(setStatus.Status.Action()), - setStatus.UnixTime.Time().Format(timeLayout), + colors.Magenta(op.Author.DisplayName()), + colors.Bold(op.Status.Action()), + op.UnixTime.Time().Format(timeLayout), ) content, lines := text.Wrap(content, maxX) @@ -324,15 +316,13 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error { y0 += lines + 2 case *bug.LabelChangeTimelineItem: - labelChange := op.(*bug.LabelChangeTimelineItem) - var added []string - for _, label := range labelChange.Added { + for _, label := range op.Added { added = append(added, colors.Bold("\""+label+"\"")) } var removed []string - for _, label := range labelChange.Removed { + for _, label := range op.Removed { removed = append(removed, colors.Bold("\""+label+"\"")) } @@ -359,9 +349,9 @@ func (sb *showBug) renderMain(g *gocui.Gui, mainView *gocui.View) error { } content := fmt.Sprintf("%s %s on %s", - colors.Magenta(labelChange.Author.DisplayName()), + colors.Magenta(op.Author.DisplayName()), action.String(), - labelChange.UnixTime.Time().Format(timeLayout), + op.UnixTime.Time().Format(timeLayout), ) content, lines := text.Wrap(content, maxX) @@ -651,13 +641,11 @@ func (sb *showBug) edit(g *gocui.Gui, v *gocui.View) error { return err } - switch op.(type) { + switch op := op.(type) { case *bug.AddCommentTimelineItem: - message := op.(*bug.AddCommentTimelineItem).Message - return editCommentWithEditor(sb.bug, op.Id(), message) + return editCommentWithEditor(sb.bug, op.Id(), op.Message) case *bug.CreateTimelineItem: - preMessage := op.(*bug.CreateTimelineItem).Message - return editCommentWithEditor(sb.bug, op.Id(), preMessage) + return editCommentWithEditor(sb.bug, op.Id(), op.Message) case *bug.LabelChangeTimelineItem: return sb.editLabels(g, snap) } diff --git a/termui/termui.go b/termui/termui.go index 9b92b536..1ef960de 100644 --- a/termui/termui.go +++ b/termui/termui.go @@ -117,8 +117,6 @@ func initGui(action func(ui *termUI) error) { } ui.gError <- err } - - return } func layout(g *gocui.Gui) error { -- cgit