Skip to content

Commit 431993b

Browse files
authored
Bump golangci-lint to v2.12.2 (#5941)
2 parents 6032225 + 37c53ac commit 431993b

12 files changed

Lines changed: 37 additions & 42 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ jobs:
195195
uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9
196196
with:
197197
# If you change this, make sure to also update scripts/golangci-lint-shim.sh
198-
version: v2.4.0
198+
version: v2.12.2
199199
upload-coverage:
200200
# List all jobs that produce coverage files
201201
needs: [unit-tests, integration-tests]

.golangci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ linters:
9999
generated: lax
100100
presets:
101101
- comments
102-
- common-false-positives
103-
- legacy
104102
- std-error-handling
105103
paths:
106104
- vendor/

pkg/cheatsheet/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func getHeader(binding *types.Binding, tr *i18n.TranslationSet) header {
196196

197197
func formatSections(tr *i18n.TranslationSet, bindingSections []*bindingSection) string {
198198
var content strings.Builder
199-
content.WriteString(fmt.Sprintf("# Lazygit %s\n", tr.Keybindings))
199+
fmt.Fprintf(&content, "# Lazygit %s\n", tr.Keybindings)
200200

201201
for _, section := range bindingSections {
202202
content.WriteString(formatTitle(section.title))

pkg/commands/patch/hunk.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ func (self *Hunk) lineCount() int {
4444

4545
// Returns all lines in the hunk, including the header line
4646
func (self *Hunk) allLines() []*PatchLine {
47-
lines := []*PatchLine{{Content: self.formatHeaderLine(), Kind: HUNK_HEADER}}
47+
lines := make([]*PatchLine, 1, 1+len(self.bodyLines))
48+
lines[0] = &PatchLine{Content: self.formatHeaderLine(), Kind: HUNK_HEADER}
4849
lines = append(lines, self.bodyLines...)
4950
return lines
5051
}

pkg/gocui/view_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/gdamore/tcell/v3"
1212
"github.com/gdamore/tcell/v3/color"
1313
"github.com/rivo/uniseg"
14+
"github.com/samber/lo"
1415
"github.com/stretchr/testify/assert"
1516
)
1617

@@ -106,10 +107,8 @@ func TestWriteString(t *testing.T) {
106107
for _, s := range test.stringsToWrite {
107108
v.writeString(s)
108109
}
109-
var resultingLines [][]string
110-
for _, l := range v.buf.lines {
111-
resultingLines = append(resultingLines, cellsToStrings(l.cells))
112-
}
110+
resultingLines := lo.Map(v.buf.lines,
111+
func(l lineType, _ int) []string { return cellsToStrings(l.cells) })
113112
assert.Equal(t, test.expectedLines, resultingLines)
114113
}
115114
}
@@ -465,11 +464,7 @@ func cellsToString(cells []cell) string {
465464
}
466465

467466
func cellsToStrings(cells []cell) []string {
468-
s := []string{}
469-
for _, c := range cells {
470-
s = append(s, c.chr)
471-
}
472-
return s
467+
return lo.Map(cells, func(c cell, _ int) string { return c.chr })
473468
}
474469

475470
func TestLineWrap(t *testing.T) {

pkg/gui/context/base_context.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (self *BaseContext) GetKey() types.ContextKey {
119119
}
120120

121121
func (self *BaseContext) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
122-
bindings := []*types.Binding{}
122+
bindings := make([]*types.Binding, 0, len(self.keybindingsFns))
123123
for i := range self.keybindingsFns {
124124
// the first binding in the bindings array takes precedence but we want the
125125
// last keybindingsFn to take precedence to we add them in reverse
@@ -216,7 +216,7 @@ func (self *BaseContext) AddOnQuitFn(fn func()) {
216216
}
217217

218218
func (self *BaseContext) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
219-
bindings := []*gocui.ViewMouseBinding{}
219+
bindings := make([]*gocui.ViewMouseBinding, 0, len(self.mouseKeybindingsFns))
220220
for i := range self.mouseKeybindingsFns {
221221
// the first binding in the bindings array takes precedence but we want the
222222
// last keybindingsFn to take precedence to we add them in reverse

pkg/gui/controllers/basic_commits_controller.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ func (self *BasicCommitsController) copyCommitAttribute(commit *models.Commit) e
157157
}
158158
}
159159

160+
commitTagsItem := &types.MenuItem{
161+
Label: self.c.Tr.CommitTags,
162+
OnPress: func() error {
163+
return self.copyCommitTagsToClipboard(commit)
164+
},
165+
Keys: menuKey('t'),
166+
}
167+
168+
if len(commit.Tags) == 0 {
169+
commitTagsItem.DisabledReason = &types.DisabledReason{Text: self.c.Tr.CommitHasNoTags}
170+
}
171+
160172
items := []*types.MenuItem{
161173
{
162174
Label: self.c.Tr.CommitHash,
@@ -207,22 +219,9 @@ func (self *BasicCommitsController) copyCommitAttribute(commit *models.Commit) e
207219
},
208220
Keys: menuKey('a'),
209221
},
222+
commitTagsItem,
210223
}
211224

212-
commitTagsItem := types.MenuItem{
213-
Label: self.c.Tr.CommitTags,
214-
OnPress: func() error {
215-
return self.copyCommitTagsToClipboard(commit)
216-
},
217-
Keys: menuKey('t'),
218-
}
219-
220-
if len(commit.Tags) == 0 {
221-
commitTagsItem.DisabledReason = &types.DisabledReason{Text: self.c.Tr.CommitHasNoTags}
222-
}
223-
224-
items = append(items, &commitTagsItem)
225-
226225
return self.c.Menu(types.CreateMenuOptions{
227226
Title: self.c.Tr.Actions.CopyCommitAttributeToClipboard,
228227
Items: items,

pkg/gui/keybindings.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,9 @@ func (gui *Gui) GetInitialKeybindings() ([]*types.Binding, []*gocui.ViewMouseBin
295295
},
296296
}
297297

298-
mouseKeybindings := []*gocui.ViewMouseBinding{}
299-
for _, c := range gui.State.Contexts.Flatten() {
298+
contexts := gui.State.Contexts.Flatten()
299+
mouseKeybindings := make([]*gocui.ViewMouseBinding, 0, len(contexts))
300+
for _, c := range contexts {
300301
viewName := c.GetViewName()
301302
for _, binding := range c.GetKeybindings(opts) {
302303
// TODO: move all mouse keybindings into the mouse keybindings approach below

pkg/integration/components/env.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package components
33
import (
44
"fmt"
55
"os"
6+
7+
"github.com/samber/lo"
68
)
79

810
const (
@@ -43,11 +45,9 @@ var hostEnvironmentAllowlist = [...]string{
4345
// Returns a copy of the environment filtered by
4446
// hostEnvironmentAllowlist
4547
func allowedHostEnvironment() []string {
46-
env := []string{}
47-
for _, envVar := range hostEnvironmentAllowlist {
48-
env = append(env, fmt.Sprintf("%s=%s", envVar, os.Getenv(envVar)))
49-
}
50-
return env
48+
return lo.Map(hostEnvironmentAllowlist[:], func(envVar string, _ int) string {
49+
return fmt.Sprintf("%s=%s", envVar, os.Getenv(envVar))
50+
})
5151
}
5252

5353
func NewTestEnvironment(rootDir string) []string {

pkg/integration/components/runner.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,15 @@ func getLazygitCommand(
256256
return nil, err
257257
}
258258

259-
cmdArgs := []string{tempLazygitPath(), "-debug", "--use-config-dir=" + paths.Config()}
260-
261259
resolvedExtraArgs := lo.Map(test.ExtraCmdArgs(), func(arg string, _ int) string {
262260
return utils.ResolvePlaceholderString(arg, map[string]string{
263261
"actualPath": paths.Actual(),
264262
"actualRepoPath": paths.ActualRepo(),
265263
})
266264
})
265+
266+
cmdArgs := make([]string, 0, 3+len(resolvedExtraArgs))
267+
cmdArgs = append(cmdArgs, tempLazygitPath(), "-debug", "--use-config-dir="+paths.Config())
267268
cmdArgs = append(cmdArgs, resolvedExtraArgs...)
268269

269270
// Use a limited environment for test isolation, including pass through

0 commit comments

Comments
 (0)