Skip to content

Commit

Permalink
Use strings.TrimSuffix(s, "\n") instead of trim.LastNewline(s).
Browse files Browse the repository at this point in the history
This is simpler and more readable, since package strings is a part of
the standard library.

Done with:

	gofmt -w -r 'trim.LastNewline(s) -> strings.TrimSuffix(s, "\n")' .
	goimports -w .
  • Loading branch information
dmitshur committed Dec 15, 2018
1 parent 4ce28f6 commit a2ccb1d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

"github.com/shurcooL/go/pipeutil"
"github.com/shurcooL/go/trim"
"github.com/shurcooL/vcsstate"
"golang.org/x/tools/go/vcs"
"gopkg.in/pipe.v2"
Expand Down Expand Up @@ -36,7 +35,7 @@ func branches(dir string, baseBranch string) (_ string, staleBranches int, _ err
// line is tab-separated local branch, commiter date.
// E.g., "master\t2016-03-03 15:01:11 -0800".
branchInfo := func(line []byte) []byte {
branchDate := strings.Split(trim.LastNewline(string(line)), "\t")
branchDate := strings.Split(strings.TrimSuffix(string(line), "\n"), "\t")
if len(branchDate) != 2 {
return []byte("error: len(branchDate) != 2")
}
Expand Down Expand Up @@ -73,7 +72,7 @@ func branches(dir string, baseBranch string) (_ string, staleBranches int, _ err
return []byte(fmt.Sprintf("%s | %s | ? | ?\n", branchDisplay, baseBranch))
}

behindAhead := strings.Split(trim.LastNewline(string(out)), "\t")
behindAhead := strings.Split(strings.TrimSuffix(string(out), "\n"), "\t")
return []byte(fmt.Sprintf("%s | %s | %s | %s\n", branchDisplay, baseBranch, behindAhead[0], behindAhead[1]))
}

Expand Down Expand Up @@ -111,7 +110,7 @@ func branchesRemote(dir string, baseBranch string) (_ string, staleBranches int,
// line is tab-separated local branch, remote branch, commiter date.
// E.g., "master\torigin/master\t2016-03-03 15:01:11 -0800".
branchRemoteInfo := func(line []byte) []byte {
branchRemoteDate := strings.Split(trim.LastNewline(string(line)), "\t")
branchRemoteDate := strings.Split(strings.TrimSuffix(string(line), "\n"), "\t")
if len(branchRemoteDate) != 3 {
return []byte("error: len(branchRemoteDate) != 3")
}
Expand Down Expand Up @@ -154,7 +153,7 @@ func branchesRemote(dir string, baseBranch string) (_ string, staleBranches int,
return []byte(fmt.Sprintf("%s | %s | | \n", branchDisplay, remoteDisplay))
}

behindAhead := strings.Split(trim.LastNewline(string(out)), "\t")
behindAhead := strings.Split(strings.TrimSuffix(string(out), "\n"), "\t")
return []byte(fmt.Sprintf("%s | %s | %s | %s\n", branchDisplay, remote, behindAhead[0], behindAhead[1]))
}

Expand Down

0 comments on commit a2ccb1d

Please sign in to comment.