1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-11-20 17:22:23 +03:00

Modernize all codes

go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...
This commit is contained in:
phanium
2025-11-12 09:19:27 +08:00
committed by Stefan Haller
parent a7126d5456
commit d88f95275f
20 changed files with 38 additions and 53 deletions

View File

@@ -218,8 +218,8 @@ func (self *CommitLoader) extractCommitFromLine(hashPool *utils.StringPool, line
var tags []string
if extraInfo != "" {
extraInfoFields := strings.Split(extraInfo, ",")
for _, extraInfoField := range extraInfoFields {
extraInfoFields := strings.SplitSeq(extraInfo, ",")
for extraInfoField := range extraInfoFields {
extraInfoField = strings.TrimSpace(extraInfoField)
re := regexp.MustCompile(`tag: (.+)`)
tagMatch := re.FindStringSubmatch(extraInfoField)

View File

@@ -32,7 +32,7 @@ func (self *FlowCommands) FinishCmdObj(branchName string) (*oscommands.CmdObj, e
suffix := strings.Replace(branchName, prefix, "", 1)
branchType := ""
for _, line := range strings.Split(strings.TrimSpace(prefixes), "\n") {
for line := range strings.SplitSeq(strings.TrimSpace(prefixes), "\n") {
if strings.HasPrefix(line, "gitflow.prefix.") && strings.HasSuffix(line, prefix) {
regex := regexp.MustCompile("gitflow.prefix.([^ ]*) .*")

View File

@@ -16,7 +16,7 @@ type FakeFieldLogger struct {
*logrus.Entry
}
func (self *FakeFieldLogger) Error(args ...interface{}) {
func (self *FakeFieldLogger) Error(args ...any) {
if len(args) != 1 {
panic("Expected exactly one argument to FakeFieldLogger.Error")
}
@@ -29,7 +29,7 @@ func (self *FakeFieldLogger) Error(args ...interface{}) {
}
}
func (self *FakeFieldLogger) Errorf(format string, args ...interface{}) {
func (self *FakeFieldLogger) Errorf(format string, args ...any) {
msg := fmt.Sprintf(format, args...)
self.loggedErrors = append(self.loggedErrors, msg)
}

View File

@@ -109,11 +109,7 @@ func (self *ConfirmationHelper) getPopupPanelWidth() int {
panelWidth := 4 * width / 7
minWidth := 80
if panelWidth < minWidth {
if width-2 < minWidth {
panelWidth = width - 2
} else {
panelWidth = minWidth
}
panelWidth = min(width-2, minWidth)
}
return panelWidth

View File

@@ -225,8 +225,8 @@ func (self *FixupHelper) blameDeletedLines(deletedLineHunks []*hunk) ([]string,
if err != nil {
return err
}
blameLines := strings.Split(strings.TrimSuffix(blameOutput, "\n"), "\n")
for _, line := range blameLines {
blameLines := strings.SplitSeq(strings.TrimSuffix(blameOutput, "\n"), "\n")
for line := range blameLines {
hashChan <- strings.Split(line, " ")[0]
}
return nil

View File

@@ -59,9 +59,9 @@ func (self *ReposHelper) getCurrentBranch(path string) string {
content := strings.TrimSpace(string(headFile))
refsPrefix := "ref: refs/heads/"
var branchDisplay string
if strings.HasPrefix(content, refsPrefix) {
if bareName, ok := strings.CutPrefix(content, refsPrefix); ok {
// is a branch
branchDisplay = strings.TrimPrefix(content, refsPrefix)
branchDisplay = bareName
} else {
// detached HEAD state, displaying short hash
branchDisplay = utils.ShortHash(content)

View File

@@ -2,6 +2,7 @@ package helpers
import (
"fmt"
mapsPkg "maps"
"math"
"strings"
@@ -194,9 +195,7 @@ func mainPanelChildren(args WindowArrangementArgs) []*boxlayout.Box {
func MergeMaps[K comparable, V any](maps ...map[K]V) map[K]V {
result := map[K]V{}
for _, currMap := range maps {
for key, value := range currMap {
result[key] = value
}
mapsPkg.Copy(result, currMap)
}
return result

View File

@@ -1116,8 +1116,8 @@ func isFixupCommit(subject string) (string, bool) {
prefixes := []string{"fixup! ", "squash! ", "amend! "}
trimPrefix := func(s string) (string, bool) {
for _, prefix := range prefixes {
if strings.HasPrefix(s, prefix) {
return strings.TrimPrefix(s, prefix), true
if trimmedSubject, ok := strings.CutPrefix(s, prefix); ok {
return trimmedSubject, true
}
}
return s, false

View File

@@ -227,7 +227,7 @@ func TestRenderCommitGraph(t *testing.T) {
lines := RenderCommitGraph(commits, hashPool.Add("blah"), getStyle)
trimmedExpectedOutput := ""
for _, line := range strings.Split(strings.TrimPrefix(test.expectedOutput, "\n"), "\n") {
for line := range strings.SplitSeq(strings.TrimPrefix(test.expectedOutput, "\n"), "\n") {
trimmedExpectedOutput += strings.TrimSpace(line) + "\n"
}

View File

@@ -34,7 +34,7 @@ func (self *MenuGenerator) call(commandOutput, filter, valueFormat, labelFormat
}
menuItems := []*commandMenuItem{}
for _, line := range strings.Split(commandOutput, "\n") {
for line := range strings.SplitSeq(commandOutput, "\n") {
if line == "" {
continue
}

View File

@@ -36,8 +36,8 @@ type TextStyle struct {
}
type Sprinter interface {
Sprint(a ...interface{}) string
Sprintf(format string, a ...interface{}) string
Sprint(a ...any) string
Sprintf(format string, a ...any) string
}
func New() TextStyle {
@@ -46,11 +46,11 @@ func New() TextStyle {
return s
}
func (b TextStyle) Sprint(a ...interface{}) string {
func (b TextStyle) Sprint(a ...any) string {
return b.Style.Sprint(a...)
}
func (b TextStyle) Sprintf(format string, a ...interface{}) string {
func (b TextStyle) Sprintf(format string, a ...any) string {
return b.Style.Sprintf(format, a...)
}

View File

@@ -5,7 +5,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/style"
)
type Key interface{} // FIXME: find out how to get `gocui.Key | rune`
type Key any // FIXME: find out how to get `gocui.Key | rune`
// Binding - a keybinding mapping a key and modifier to a handler. The keypress
// is only handled if the given view has focus, or handled globally if the view

View File

@@ -29,13 +29,10 @@ func (gui *Gui) linesToReadFromCmdTask(v *gocui.View) tasks.LinesToRead {
// scrollbar go to its minimum height, so that the scrollbar thumb doesn't
// change size as you scroll down.
minScrollbarHeight := 1
linesToReadForAccurateScrollbar := height*(height-1)/minScrollbarHeight + oy
// However, cap it at some arbitrary max limit, so that we don't get
// performance problems for huge monitors or tiny font sizes
if linesToReadForAccurateScrollbar > 5000 {
linesToReadForAccurateScrollbar = 5000
}
linesToReadForAccurateScrollbar := min(
// However, cap it at some arbitrary max limit, so that we don't get
// performance problems for huge monitors or tiny font sizes
height*(height-1)/minScrollbarHeight+oy, 5000)
return tasks.LinesToRead{
Total: linesToReadForAccurateScrollbar,

View File

@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io/fs"
"slices"
"strings"
"dario.cat/mergo"
@@ -37,10 +38,8 @@ func NewTranslationSetFromConfig(log *logrus.Entry, configLanguage string) (*Tra
return EnglishTranslationSet(), nil
}
for _, key := range languageCodes {
if key == configLanguage {
return newTranslationSet(log, configLanguage)
}
if slices.Contains(languageCodes, configLanguage) {
return newTranslationSet(log, configLanguage)
}
// Configuring a language that we don't have a translation for *is* an

View File

@@ -15,7 +15,7 @@ import (
type RunTestArgs struct {
Tests []*IntegrationTest
Logf func(format string, formatArgs ...interface{})
Logf func(format string, formatArgs ...any)
RunCmd func(cmd *exec.Cmd) (int, error)
TestWrapper func(test *IntegrationTest, f func() error)
Sandbox bool

View File

@@ -114,7 +114,7 @@ func setComment(yamlNode *yaml.Node, description string) {
"\n")
}
func (n *Node) MarshalYAML() (interface{}, error) {
func (n *Node) MarshalYAML() (any, error) {
node := yaml.Node{
Kind: yaml.MappingNode,
}

View File

@@ -117,12 +117,10 @@ func TestNewCmdTask(t *testing.T) {
fn := manager.NewCmdTask(start, "prefix\n", LinesToRead{20, -1, nil}, onDone)
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
wg.Go(func() {
time.Sleep(100 * time.Millisecond)
close(stop)
wg.Done()
}()
})
_ = fn(TaskOpts{Stop: stop, InitialContentLoaded: func() { task.Done() }})
wg.Wait()
@@ -252,12 +250,10 @@ func TestNewCmdTaskRefresh(t *testing.T) {
fn := manager.NewCmdTask(start, "", s.linesToRead, func() {})
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
wg.Go(func() {
time.Sleep(100 * time.Millisecond)
close(stop)
wg.Done()
}()
})
_ = fn(TaskOpts{Stop: stop, InitialContentLoaded: func() { task.Done() }})
wg.Wait()

View File

@@ -51,10 +51,8 @@ func PrevIntInCycle(sl []int, current int) int {
func StringArraysOverlap(strArrA []string, strArrB []string) bool {
for _, first := range strArrA {
for _, second := range strArrB {
if first == second {
return true
}
if slices.Contains(strArrB, first) {
return true
}
}

View File

@@ -6,7 +6,7 @@ import (
"text/template"
)
func ResolveTemplate(templateStr string, object interface{}, funcs template.FuncMap) (string, error) {
func ResolveTemplate(templateStr string, object any, funcs template.FuncMap) (string, error) {
tmpl, err := template.New("template").Funcs(funcs).Option("missingkey=error").Parse(templateStr)
if err != nil {
return "", err

View File

@@ -30,7 +30,7 @@ func SortRange(x int, y int) (int, int) {
return y, x
}
func AsJson(i interface{}) string {
func AsJson(i any) string {
bytes, _ := json.MarshalIndent(i, "", " ")
return string(bytes)
}