diff --git a/pkg/commands/git_commands/commit_loader.go b/pkg/commands/git_commands/commit_loader.go index 72adf1b69..dcf66ddee 100644 --- a/pkg/commands/git_commands/commit_loader.go +++ b/pkg/commands/git_commands/commit_loader.go @@ -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) diff --git a/pkg/commands/git_commands/flow.go b/pkg/commands/git_commands/flow.go index a5aa9d4dc..fc00c11a1 100644 --- a/pkg/commands/git_commands/flow.go +++ b/pkg/commands/git_commands/flow.go @@ -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.([^ ]*) .*") diff --git a/pkg/fakes/log.go b/pkg/fakes/log.go index fc68f23c1..9cb277663 100644 --- a/pkg/fakes/log.go +++ b/pkg/fakes/log.go @@ -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) } diff --git a/pkg/gui/controllers/helpers/confirmation_helper.go b/pkg/gui/controllers/helpers/confirmation_helper.go index 4a746819b..1599d5e86 100644 --- a/pkg/gui/controllers/helpers/confirmation_helper.go +++ b/pkg/gui/controllers/helpers/confirmation_helper.go @@ -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 diff --git a/pkg/gui/controllers/helpers/fixup_helper.go b/pkg/gui/controllers/helpers/fixup_helper.go index a435d188d..c082becc2 100644 --- a/pkg/gui/controllers/helpers/fixup_helper.go +++ b/pkg/gui/controllers/helpers/fixup_helper.go @@ -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 diff --git a/pkg/gui/controllers/helpers/repos_helper.go b/pkg/gui/controllers/helpers/repos_helper.go index decebba36..158606b01 100644 --- a/pkg/gui/controllers/helpers/repos_helper.go +++ b/pkg/gui/controllers/helpers/repos_helper.go @@ -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) diff --git a/pkg/gui/controllers/helpers/window_arrangement_helper.go b/pkg/gui/controllers/helpers/window_arrangement_helper.go index f2d3ff012..04f31d0fd 100644 --- a/pkg/gui/controllers/helpers/window_arrangement_helper.go +++ b/pkg/gui/controllers/helpers/window_arrangement_helper.go @@ -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 diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 9badaf1ed..3168b7ff3 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -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 diff --git a/pkg/gui/presentation/graph/graph_test.go b/pkg/gui/presentation/graph/graph_test.go index e567ec674..a756f8aa4 100644 --- a/pkg/gui/presentation/graph/graph_test.go +++ b/pkg/gui/presentation/graph/graph_test.go @@ -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" } diff --git a/pkg/gui/services/custom_commands/menu_generator.go b/pkg/gui/services/custom_commands/menu_generator.go index 4a73fe433..95929ee83 100644 --- a/pkg/gui/services/custom_commands/menu_generator.go +++ b/pkg/gui/services/custom_commands/menu_generator.go @@ -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 } diff --git a/pkg/gui/style/text_style.go b/pkg/gui/style/text_style.go index f0a1da0e6..44b2fbf55 100644 --- a/pkg/gui/style/text_style.go +++ b/pkg/gui/style/text_style.go @@ -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...) } diff --git a/pkg/gui/types/keybindings.go b/pkg/gui/types/keybindings.go index ac3ce049d..9289dbe9a 100644 --- a/pkg/gui/types/keybindings.go +++ b/pkg/gui/types/keybindings.go @@ -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 diff --git a/pkg/gui/view_helpers.go b/pkg/gui/view_helpers.go index 10cb8d48b..3dfea4c39 100644 --- a/pkg/gui/view_helpers.go +++ b/pkg/gui/view_helpers.go @@ -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, diff --git a/pkg/i18n/i18n.go b/pkg/i18n/i18n.go index 528f3815a..55c230883 100644 --- a/pkg/i18n/i18n.go +++ b/pkg/i18n/i18n.go @@ -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 diff --git a/pkg/integration/components/runner.go b/pkg/integration/components/runner.go index f32fde618..83ddfe66d 100644 --- a/pkg/integration/components/runner.go +++ b/pkg/integration/components/runner.go @@ -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 diff --git a/pkg/jsonschema/generate_config_docs.go b/pkg/jsonschema/generate_config_docs.go index b9de5c54b..ba245e99a 100644 --- a/pkg/jsonschema/generate_config_docs.go +++ b/pkg/jsonschema/generate_config_docs.go @@ -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, } diff --git a/pkg/tasks/tasks_test.go b/pkg/tasks/tasks_test.go index c7a499d46..452b91eaf 100644 --- a/pkg/tasks/tasks_test.go +++ b/pkg/tasks/tasks_test.go @@ -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() diff --git a/pkg/utils/slice.go b/pkg/utils/slice.go index 0dc9e64e4..0f9109a2f 100644 --- a/pkg/utils/slice.go +++ b/pkg/utils/slice.go @@ -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 } } diff --git a/pkg/utils/template.go b/pkg/utils/template.go index 9b7f544d1..f5fea99e4 100644 --- a/pkg/utils/template.go +++ b/pkg/utils/template.go @@ -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 diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 950555512..7eb24b736 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -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) }