various cleanups suggested by golang-ci

Michael Muré created

Change summary

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(-)

Detailed changes

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")
 	}

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

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))

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

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

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

termui/termui.go 🔗

@@ -117,8 +117,6 @@ func initGui(action func(ui *termUI) error) {
 		}
 		ui.gError <- err
 	}
-
-	return
 }
 
 func layout(g *gocui.Gui) error {