Skip to content

Commit 3d5b22f

Browse files
authored
Modernize all codes (#5036)
go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...
2 parents a7126d5 + d88f952 commit 3d5b22f

File tree

20 files changed

+38
-53
lines changed

20 files changed

+38
-53
lines changed

pkg/commands/git_commands/commit_loader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ func (self *CommitLoader) extractCommitFromLine(hashPool *utils.StringPool, line
218218
var tags []string
219219

220220
if extraInfo != "" {
221-
extraInfoFields := strings.Split(extraInfo, ",")
222-
for _, extraInfoField := range extraInfoFields {
221+
extraInfoFields := strings.SplitSeq(extraInfo, ",")
222+
for extraInfoField := range extraInfoFields {
223223
extraInfoField = strings.TrimSpace(extraInfoField)
224224
re := regexp.MustCompile(`tag: (.+)`)
225225
tagMatch := re.FindStringSubmatch(extraInfoField)

pkg/commands/git_commands/flow.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (self *FlowCommands) FinishCmdObj(branchName string) (*oscommands.CmdObj, e
3232
suffix := strings.Replace(branchName, prefix, "", 1)
3333

3434
branchType := ""
35-
for _, line := range strings.Split(strings.TrimSpace(prefixes), "\n") {
35+
for line := range strings.SplitSeq(strings.TrimSpace(prefixes), "\n") {
3636
if strings.HasPrefix(line, "gitflow.prefix.") && strings.HasSuffix(line, prefix) {
3737

3838
regex := regexp.MustCompile("gitflow.prefix.([^ ]*) .*")

pkg/fakes/log.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type FakeFieldLogger struct {
1616
*logrus.Entry
1717
}
1818

19-
func (self *FakeFieldLogger) Error(args ...interface{}) {
19+
func (self *FakeFieldLogger) Error(args ...any) {
2020
if len(args) != 1 {
2121
panic("Expected exactly one argument to FakeFieldLogger.Error")
2222
}
@@ -29,7 +29,7 @@ func (self *FakeFieldLogger) Error(args ...interface{}) {
2929
}
3030
}
3131

32-
func (self *FakeFieldLogger) Errorf(format string, args ...interface{}) {
32+
func (self *FakeFieldLogger) Errorf(format string, args ...any) {
3333
msg := fmt.Sprintf(format, args...)
3434
self.loggedErrors = append(self.loggedErrors, msg)
3535
}

pkg/gui/controllers/helpers/confirmation_helper.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,7 @@ func (self *ConfirmationHelper) getPopupPanelWidth() int {
109109
panelWidth := 4 * width / 7
110110
minWidth := 80
111111
if panelWidth < minWidth {
112-
if width-2 < minWidth {
113-
panelWidth = width - 2
114-
} else {
115-
panelWidth = minWidth
116-
}
112+
panelWidth = min(width-2, minWidth)
117113
}
118114

119115
return panelWidth

pkg/gui/controllers/helpers/fixup_helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ func (self *FixupHelper) blameDeletedLines(deletedLineHunks []*hunk) ([]string,
225225
if err != nil {
226226
return err
227227
}
228-
blameLines := strings.Split(strings.TrimSuffix(blameOutput, "\n"), "\n")
229-
for _, line := range blameLines {
228+
blameLines := strings.SplitSeq(strings.TrimSuffix(blameOutput, "\n"), "\n")
229+
for line := range blameLines {
230230
hashChan <- strings.Split(line, " ")[0]
231231
}
232232
return nil

pkg/gui/controllers/helpers/repos_helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ func (self *ReposHelper) getCurrentBranch(path string) string {
5959
content := strings.TrimSpace(string(headFile))
6060
refsPrefix := "ref: refs/heads/"
6161
var branchDisplay string
62-
if strings.HasPrefix(content, refsPrefix) {
62+
if bareName, ok := strings.CutPrefix(content, refsPrefix); ok {
6363
// is a branch
64-
branchDisplay = strings.TrimPrefix(content, refsPrefix)
64+
branchDisplay = bareName
6565
} else {
6666
// detached HEAD state, displaying short hash
6767
branchDisplay = utils.ShortHash(content)

pkg/gui/controllers/helpers/window_arrangement_helper.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package helpers
22

33
import (
44
"fmt"
5+
mapsPkg "maps"
56
"math"
67
"strings"
78

@@ -194,9 +195,7 @@ func mainPanelChildren(args WindowArrangementArgs) []*boxlayout.Box {
194195
func MergeMaps[K comparable, V any](maps ...map[K]V) map[K]V {
195196
result := map[K]V{}
196197
for _, currMap := range maps {
197-
for key, value := range currMap {
198-
result[key] = value
199-
}
198+
mapsPkg.Copy(result, currMap)
200199
}
201200

202201
return result

pkg/gui/controllers/local_commits_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,8 +1116,8 @@ func isFixupCommit(subject string) (string, bool) {
11161116
prefixes := []string{"fixup! ", "squash! ", "amend! "}
11171117
trimPrefix := func(s string) (string, bool) {
11181118
for _, prefix := range prefixes {
1119-
if strings.HasPrefix(s, prefix) {
1120-
return strings.TrimPrefix(s, prefix), true
1119+
if trimmedSubject, ok := strings.CutPrefix(s, prefix); ok {
1120+
return trimmedSubject, true
11211121
}
11221122
}
11231123
return s, false

pkg/gui/presentation/graph/graph_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func TestRenderCommitGraph(t *testing.T) {
227227
lines := RenderCommitGraph(commits, hashPool.Add("blah"), getStyle)
228228

229229
trimmedExpectedOutput := ""
230-
for _, line := range strings.Split(strings.TrimPrefix(test.expectedOutput, "\n"), "\n") {
230+
for line := range strings.SplitSeq(strings.TrimPrefix(test.expectedOutput, "\n"), "\n") {
231231
trimmedExpectedOutput += strings.TrimSpace(line) + "\n"
232232
}
233233

pkg/gui/services/custom_commands/menu_generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (self *MenuGenerator) call(commandOutput, filter, valueFormat, labelFormat
3434
}
3535

3636
menuItems := []*commandMenuItem{}
37-
for _, line := range strings.Split(commandOutput, "\n") {
37+
for line := range strings.SplitSeq(commandOutput, "\n") {
3838
if line == "" {
3939
continue
4040
}

0 commit comments

Comments
 (0)