mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Use lo.Map instead of manual append loops
Not only is this nicer code (and more idiomatic at least in this code base), but it also avoids linter warnings about missing preallocations (lo.Map does preallocate the result array).
This commit is contained in:
parent
1db9f9cdb8
commit
f0ccb937d3
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/gdamore/tcell/v3"
|
||||
"github.com/gdamore/tcell/v3/color"
|
||||
"github.com/rivo/uniseg"
|
||||
"github.com/samber/lo"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
@ -106,10 +107,8 @@ func TestWriteString(t *testing.T) {
|
|||
for _, s := range test.stringsToWrite {
|
||||
v.writeString(s)
|
||||
}
|
||||
var resultingLines [][]string
|
||||
for _, l := range v.buf.lines {
|
||||
resultingLines = append(resultingLines, cellsToStrings(l.cells))
|
||||
}
|
||||
resultingLines := lo.Map(v.buf.lines,
|
||||
func(l lineType, _ int) []string { return cellsToStrings(l.cells) })
|
||||
assert.Equal(t, test.expectedLines, resultingLines)
|
||||
}
|
||||
}
|
||||
|
|
@ -465,11 +464,7 @@ func cellsToString(cells []cell) string {
|
|||
}
|
||||
|
||||
func cellsToStrings(cells []cell) []string {
|
||||
s := []string{}
|
||||
for _, c := range cells {
|
||||
s = append(s, c.chr)
|
||||
}
|
||||
return s
|
||||
return lo.Map(cells, func(c cell, _ int) string { return c.chr })
|
||||
}
|
||||
|
||||
func TestLineWrap(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package components
|
|||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -43,11 +45,9 @@ var hostEnvironmentAllowlist = [...]string{
|
|||
// Returns a copy of the environment filtered by
|
||||
// hostEnvironmentAllowlist
|
||||
func allowedHostEnvironment() []string {
|
||||
env := []string{}
|
||||
for _, envVar := range hostEnvironmentAllowlist {
|
||||
env = append(env, fmt.Sprintf("%s=%s", envVar, os.Getenv(envVar)))
|
||||
}
|
||||
return env
|
||||
return lo.Map(hostEnvironmentAllowlist[:], func(envVar string, _ int) string {
|
||||
return fmt.Sprintf("%s=%s", envVar, os.Getenv(envVar))
|
||||
})
|
||||
}
|
||||
|
||||
func NewTestEnvironment(rootDir string) []string {
|
||||
|
|
|
|||
Loading…
Reference in a new issue