mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-11-22 04:42:37 +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:
@@ -218,8 +218,8 @@ func (self *CommitLoader) extractCommitFromLine(hashPool *utils.StringPool, line
|
|||||||
var tags []string
|
var tags []string
|
||||||
|
|
||||||
if extraInfo != "" {
|
if extraInfo != "" {
|
||||||
extraInfoFields := strings.Split(extraInfo, ",")
|
extraInfoFields := strings.SplitSeq(extraInfo, ",")
|
||||||
for _, extraInfoField := range extraInfoFields {
|
for extraInfoField := range extraInfoFields {
|
||||||
extraInfoField = strings.TrimSpace(extraInfoField)
|
extraInfoField = strings.TrimSpace(extraInfoField)
|
||||||
re := regexp.MustCompile(`tag: (.+)`)
|
re := regexp.MustCompile(`tag: (.+)`)
|
||||||
tagMatch := re.FindStringSubmatch(extraInfoField)
|
tagMatch := re.FindStringSubmatch(extraInfoField)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func (self *FlowCommands) FinishCmdObj(branchName string) (*oscommands.CmdObj, e
|
|||||||
suffix := strings.Replace(branchName, prefix, "", 1)
|
suffix := strings.Replace(branchName, prefix, "", 1)
|
||||||
|
|
||||||
branchType := ""
|
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) {
|
if strings.HasPrefix(line, "gitflow.prefix.") && strings.HasSuffix(line, prefix) {
|
||||||
|
|
||||||
regex := regexp.MustCompile("gitflow.prefix.([^ ]*) .*")
|
regex := regexp.MustCompile("gitflow.prefix.([^ ]*) .*")
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type FakeFieldLogger struct {
|
|||||||
*logrus.Entry
|
*logrus.Entry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *FakeFieldLogger) Error(args ...interface{}) {
|
func (self *FakeFieldLogger) Error(args ...any) {
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
panic("Expected exactly one argument to FakeFieldLogger.Error")
|
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...)
|
msg := fmt.Sprintf(format, args...)
|
||||||
self.loggedErrors = append(self.loggedErrors, msg)
|
self.loggedErrors = append(self.loggedErrors, msg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,11 +109,7 @@ func (self *ConfirmationHelper) getPopupPanelWidth() int {
|
|||||||
panelWidth := 4 * width / 7
|
panelWidth := 4 * width / 7
|
||||||
minWidth := 80
|
minWidth := 80
|
||||||
if panelWidth < minWidth {
|
if panelWidth < minWidth {
|
||||||
if width-2 < minWidth {
|
panelWidth = min(width-2, minWidth)
|
||||||
panelWidth = width - 2
|
|
||||||
} else {
|
|
||||||
panelWidth = minWidth
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return panelWidth
|
return panelWidth
|
||||||
|
|||||||
@@ -225,8 +225,8 @@ func (self *FixupHelper) blameDeletedLines(deletedLineHunks []*hunk) ([]string,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
blameLines := strings.Split(strings.TrimSuffix(blameOutput, "\n"), "\n")
|
blameLines := strings.SplitSeq(strings.TrimSuffix(blameOutput, "\n"), "\n")
|
||||||
for _, line := range blameLines {
|
for line := range blameLines {
|
||||||
hashChan <- strings.Split(line, " ")[0]
|
hashChan <- strings.Split(line, " ")[0]
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -59,9 +59,9 @@ func (self *ReposHelper) getCurrentBranch(path string) string {
|
|||||||
content := strings.TrimSpace(string(headFile))
|
content := strings.TrimSpace(string(headFile))
|
||||||
refsPrefix := "ref: refs/heads/"
|
refsPrefix := "ref: refs/heads/"
|
||||||
var branchDisplay string
|
var branchDisplay string
|
||||||
if strings.HasPrefix(content, refsPrefix) {
|
if bareName, ok := strings.CutPrefix(content, refsPrefix); ok {
|
||||||
// is a branch
|
// is a branch
|
||||||
branchDisplay = strings.TrimPrefix(content, refsPrefix)
|
branchDisplay = bareName
|
||||||
} else {
|
} else {
|
||||||
// detached HEAD state, displaying short hash
|
// detached HEAD state, displaying short hash
|
||||||
branchDisplay = utils.ShortHash(content)
|
branchDisplay = utils.ShortHash(content)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package helpers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
mapsPkg "maps"
|
||||||
"math"
|
"math"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -194,9 +195,7 @@ func mainPanelChildren(args WindowArrangementArgs) []*boxlayout.Box {
|
|||||||
func MergeMaps[K comparable, V any](maps ...map[K]V) map[K]V {
|
func MergeMaps[K comparable, V any](maps ...map[K]V) map[K]V {
|
||||||
result := map[K]V{}
|
result := map[K]V{}
|
||||||
for _, currMap := range maps {
|
for _, currMap := range maps {
|
||||||
for key, value := range currMap {
|
mapsPkg.Copy(result, currMap)
|
||||||
result[key] = value
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -1116,8 +1116,8 @@ func isFixupCommit(subject string) (string, bool) {
|
|||||||
prefixes := []string{"fixup! ", "squash! ", "amend! "}
|
prefixes := []string{"fixup! ", "squash! ", "amend! "}
|
||||||
trimPrefix := func(s string) (string, bool) {
|
trimPrefix := func(s string) (string, bool) {
|
||||||
for _, prefix := range prefixes {
|
for _, prefix := range prefixes {
|
||||||
if strings.HasPrefix(s, prefix) {
|
if trimmedSubject, ok := strings.CutPrefix(s, prefix); ok {
|
||||||
return strings.TrimPrefix(s, prefix), true
|
return trimmedSubject, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s, false
|
return s, false
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ func TestRenderCommitGraph(t *testing.T) {
|
|||||||
lines := RenderCommitGraph(commits, hashPool.Add("blah"), getStyle)
|
lines := RenderCommitGraph(commits, hashPool.Add("blah"), getStyle)
|
||||||
|
|
||||||
trimmedExpectedOutput := ""
|
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"
|
trimmedExpectedOutput += strings.TrimSpace(line) + "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func (self *MenuGenerator) call(commandOutput, filter, valueFormat, labelFormat
|
|||||||
}
|
}
|
||||||
|
|
||||||
menuItems := []*commandMenuItem{}
|
menuItems := []*commandMenuItem{}
|
||||||
for _, line := range strings.Split(commandOutput, "\n") {
|
for line := range strings.SplitSeq(commandOutput, "\n") {
|
||||||
if line == "" {
|
if line == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ type TextStyle struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Sprinter interface {
|
type Sprinter interface {
|
||||||
Sprint(a ...interface{}) string
|
Sprint(a ...any) string
|
||||||
Sprintf(format string, a ...interface{}) string
|
Sprintf(format string, a ...any) string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() TextStyle {
|
func New() TextStyle {
|
||||||
@@ -46,11 +46,11 @@ func New() TextStyle {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b TextStyle) Sprint(a ...interface{}) string {
|
func (b TextStyle) Sprint(a ...any) string {
|
||||||
return b.Style.Sprint(a...)
|
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...)
|
return b.Style.Sprintf(format, a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
"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
|
// 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
|
// is only handled if the given view has focus, or handled globally if the view
|
||||||
|
|||||||
@@ -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
|
// scrollbar go to its minimum height, so that the scrollbar thumb doesn't
|
||||||
// change size as you scroll down.
|
// change size as you scroll down.
|
||||||
minScrollbarHeight := 1
|
minScrollbarHeight := 1
|
||||||
linesToReadForAccurateScrollbar := height*(height-1)/minScrollbarHeight + oy
|
linesToReadForAccurateScrollbar := min(
|
||||||
|
// However, cap it at some arbitrary max limit, so that we don't get
|
||||||
// However, cap it at some arbitrary max limit, so that we don't get
|
// performance problems for huge monitors or tiny font sizes
|
||||||
// performance problems for huge monitors or tiny font sizes
|
height*(height-1)/minScrollbarHeight+oy, 5000)
|
||||||
if linesToReadForAccurateScrollbar > 5000 {
|
|
||||||
linesToReadForAccurateScrollbar = 5000
|
|
||||||
}
|
|
||||||
|
|
||||||
return tasks.LinesToRead{
|
return tasks.LinesToRead{
|
||||||
Total: linesToReadForAccurateScrollbar,
|
Total: linesToReadForAccurateScrollbar,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"dario.cat/mergo"
|
"dario.cat/mergo"
|
||||||
@@ -37,10 +38,8 @@ func NewTranslationSetFromConfig(log *logrus.Entry, configLanguage string) (*Tra
|
|||||||
return EnglishTranslationSet(), nil
|
return EnglishTranslationSet(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, key := range languageCodes {
|
if slices.Contains(languageCodes, configLanguage) {
|
||||||
if key == configLanguage {
|
return newTranslationSet(log, configLanguage)
|
||||||
return newTranslationSet(log, configLanguage)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configuring a language that we don't have a translation for *is* an
|
// Configuring a language that we don't have a translation for *is* an
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
|
|
||||||
type RunTestArgs struct {
|
type RunTestArgs struct {
|
||||||
Tests []*IntegrationTest
|
Tests []*IntegrationTest
|
||||||
Logf func(format string, formatArgs ...interface{})
|
Logf func(format string, formatArgs ...any)
|
||||||
RunCmd func(cmd *exec.Cmd) (int, error)
|
RunCmd func(cmd *exec.Cmd) (int, error)
|
||||||
TestWrapper func(test *IntegrationTest, f func() error)
|
TestWrapper func(test *IntegrationTest, f func() error)
|
||||||
Sandbox bool
|
Sandbox bool
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ func setComment(yamlNode *yaml.Node, description string) {
|
|||||||
"\n")
|
"\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) MarshalYAML() (interface{}, error) {
|
func (n *Node) MarshalYAML() (any, error) {
|
||||||
node := yaml.Node{
|
node := yaml.Node{
|
||||||
Kind: yaml.MappingNode,
|
Kind: yaml.MappingNode,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,12 +117,10 @@ func TestNewCmdTask(t *testing.T) {
|
|||||||
|
|
||||||
fn := manager.NewCmdTask(start, "prefix\n", LinesToRead{20, -1, nil}, onDone)
|
fn := manager.NewCmdTask(start, "prefix\n", LinesToRead{20, -1, nil}, onDone)
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
close(stop)
|
close(stop)
|
||||||
wg.Done()
|
})
|
||||||
}()
|
|
||||||
_ = fn(TaskOpts{Stop: stop, InitialContentLoaded: func() { task.Done() }})
|
_ = fn(TaskOpts{Stop: stop, InitialContentLoaded: func() { task.Done() }})
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
@@ -252,12 +250,10 @@ func TestNewCmdTaskRefresh(t *testing.T) {
|
|||||||
|
|
||||||
fn := manager.NewCmdTask(start, "", s.linesToRead, func() {})
|
fn := manager.NewCmdTask(start, "", s.linesToRead, func() {})
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
wg.Add(1)
|
wg.Go(func() {
|
||||||
go func() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
close(stop)
|
close(stop)
|
||||||
wg.Done()
|
})
|
||||||
}()
|
|
||||||
_ = fn(TaskOpts{Stop: stop, InitialContentLoaded: func() { task.Done() }})
|
_ = fn(TaskOpts{Stop: stop, InitialContentLoaded: func() { task.Done() }})
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|||||||
@@ -51,10 +51,8 @@ func PrevIntInCycle(sl []int, current int) int {
|
|||||||
|
|
||||||
func StringArraysOverlap(strArrA []string, strArrB []string) bool {
|
func StringArraysOverlap(strArrA []string, strArrB []string) bool {
|
||||||
for _, first := range strArrA {
|
for _, first := range strArrA {
|
||||||
for _, second := range strArrB {
|
if slices.Contains(strArrB, first) {
|
||||||
if first == second {
|
return true
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"text/template"
|
"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)
|
tmpl, err := template.New("template").Funcs(funcs).Option("missingkey=error").Parse(templateStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func SortRange(x int, y int) (int, int) {
|
|||||||
return y, x
|
return y, x
|
||||||
}
|
}
|
||||||
|
|
||||||
func AsJson(i interface{}) string {
|
func AsJson(i any) string {
|
||||||
bytes, _ := json.MarshalIndent(i, "", " ")
|
bytes, _ := json.MarshalIndent(i, "", " ")
|
||||||
return string(bytes)
|
return string(bytes)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user