1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-03 12:22:34 +03:00

Enable intrange linter, and fix warnings

This commit is contained in:
Stefan Haller
2025-06-30 11:03:00 +02:00
parent 1e92d8b7f3
commit 0471dbaa84
21 changed files with 35 additions and 34 deletions

View File

@ -5,6 +5,7 @@ linters:
enable:
- copyloopvar
- exhaustive
- intrange
- makezero
- nakedret
- nolintlint

View File

@ -28,7 +28,7 @@ func (self *gitCmdObjRunner) Run(cmdObj *oscommands.CmdObj) error {
func (self *gitCmdObjRunner) RunWithOutput(cmdObj *oscommands.CmdObj) (string, error) {
var output string
var err error
for i := 0; i < RetryCount; i++ {
for range RetryCount {
newCmdObj := cmdObj.Clone()
output, err = self.innerRunner.RunWithOutput(newCmdObj)
@ -47,7 +47,7 @@ func (self *gitCmdObjRunner) RunWithOutput(cmdObj *oscommands.CmdObj) (string, e
func (self *gitCmdObjRunner) RunWithOutputs(cmdObj *oscommands.CmdObj) (string, string, error) {
var stdout, stderr string
var err error
for i := 0; i < RetryCount; i++ {
for range RetryCount {
newCmdObj := cmdObj.Clone()
stdout, stderr, err = self.innerRunner.RunWithOutputs(newCmdObj)

View File

@ -222,7 +222,7 @@ func (c *OSCommand) PipeCommands(cmdObjs ...*CmdObj) error {
c.LogCommand(logCmdStr, true)
for i := 0; i < len(cmds)-1; i++ {
for i := range len(cmds) - 1 {
stdout, err := cmds[i].StdoutPipe()
if err != nil {
return err

View File

@ -56,7 +56,7 @@ func (self *Patch) HunkStartIdx(hunkIndex int) int {
hunkIndex = lo.Clamp(hunkIndex, 0, len(self.hunks)-1)
result := len(self.header)
for i := 0; i < hunkIndex; i++ {
for i := range hunkIndex {
result += self.hunks[i].lineCount()
}
return result

View File

@ -91,7 +91,7 @@ func (p *PatchBuilder) addFileWhole(info *fileInfo) {
// add every line index
// TODO: add tests and then use lo.Range to simplify
info.includedLineIndices = make([]int, lineCount)
for i := 0; i < lineCount; i++ {
for i := range lineCount {
info.includedLineIndices[i] = i
}
}

View File

@ -56,7 +56,7 @@ func validateKeybindingsRecurse(path string, node any) error {
}
}
} else if value.Kind() == reflect.Slice {
for i := 0; i < value.Len(); i++ {
for i := range value.Len() {
if err := validateKeybindingsRecurse(
fmt.Sprintf("%s[%d]", path, i), value.Index(i).Interface()); err != nil {
return err

View File

@ -257,11 +257,11 @@ func TestListRenderer_ModelIndexToViewIndex_and_back(t *testing.T) {
// Need to render first so that it knows the non-model items
self.renderLines(-1, -1)
for i := 0; i < len(s.modelIndices); i++ {
for i := range len(s.modelIndices) {
assert.Equal(t, s.expectedViewIndices[i], self.ModelIndexToViewIndex(s.modelIndices[i]))
}
for i := 0; i < len(s.viewIndices); i++ {
for i := range len(s.viewIndices) {
assert.Equal(t, s.expectedModelIndices[i], self.ViewIndexToModelIndex(s.viewIndices[i]))
}
})

View File

@ -180,7 +180,7 @@ func (self *FilesController) Explode(v *gocui.View, onDone func()) {
self.c.OnWorker(func(_ gocui.Task) error {
max := 25
for i := 0; i < max; i++ {
for i := range max {
image := getExplodeImage(width, height, i, max)
style := styles[(i*len(styles)/max)%len(styles)]
coloredImage := style.Sprint(image)
@ -229,8 +229,8 @@ func getExplodeImage(width int, height int, frame int, max int) string {
innerRadius = (progress - 0.5) * 2 * maxRadius
}
for y := 0; y < height; y++ {
for x := 0; x < width; x++ {
for y := range height {
for x := range width {
// calculate distance from center, scale x by 2 to compensate for character aspect ratio
distance := math.Hypot(float64(x-centerX), float64(y-centerY)*2)

View File

@ -79,7 +79,7 @@ func RenderAux(pipeSets [][]Pipe, commits []*models.Commit, selectedCommitHashPt
wg := sync.WaitGroup{}
wg.Add(maxProcs)
for i := 0; i < maxProcs; i++ {
for i := range maxProcs {
go func() {
from := i * perProc
to := (i + 1) * perProc

View File

@ -579,7 +579,7 @@ func generateCommits(hashPool *utils.StringPool, count int) []*models.Commit {
parentCount := rnd.Intn(2) + 1
parentHashes := currentCommit.Parents()
for j := 0; j < parentCount; j++ {
for j := range parentCount {
reuseParent := rnd.Intn(6) != 1 && j <= len(pool)-1 && j != 0
var newParent *models.Commit
if reuseParent {

View File

@ -33,7 +33,7 @@ func (self *CommitDescriptionPanelDriver) AddNewline() *CommitDescriptionPanelDr
func (self *CommitDescriptionPanelDriver) GoToBeginning() *CommitDescriptionPanelDriver {
numLines := len(self.getViewDriver().getView().BufferLines())
for i := 0; i < numLines; i++ {
for range numLines {
self.t.pressFast("<up>")
}

View File

@ -53,7 +53,7 @@ func RunTests(args RunTestArgs) error {
filepath.Join(testDir, test.Name()),
)
for i := 0; i < args.MaxAttempts; i++ {
for i := range args.MaxAttempts {
err := runTest(test, args, paths, projectRootDir, gitVersion)
if err != nil {
if i == args.MaxAttempts-1 {

View File

@ -257,7 +257,7 @@ func (self *Shell) CreateNCommitsStartingAt(n, startIndex int) *Shell {
// Only to be used in demos, because the list might change and we don't want
// tests to break when it does.
func (self *Shell) CreateNCommitsWithRandomMessages(n int) *Shell {
for i := 0; i < n; i++ {
for i := range n {
file := RandomFiles[i]
self.CreateFileAndAdd(
file.Name,
@ -286,7 +286,7 @@ func (self *Shell) CreateRepoHistory() *Shell {
totalCommits := 0
// Generate commits
for i := 0; i < numInitialCommits; i++ {
for i := range numInitialCommits {
author := authors[i%numAuthors]
commitMessage := RandomCommitMessages[totalCommits%len(RandomCommitMessages)]
@ -296,7 +296,7 @@ func (self *Shell) CreateRepoHistory() *Shell {
}
// Generate branches and merges
for i := 0; i < numBranches; i++ {
for i := range numBranches {
// We'll have one author creating all the commits in the branch
author := authors[i%numAuthors]
branchName := RandomBranchNames[i%len(RandomBranchNames)]
@ -309,7 +309,7 @@ func (self *Shell) CreateRepoHistory() *Shell {
self.NewBranchFrom(branchName, fmt.Sprintf("master~%d", commitOffset))
numCommitsInBranch := rand.Intn(maxCommitsPerBranch) + 1
for j := 0; j < numCommitsInBranch; j++ {
for range numCommitsInBranch {
commitMessage := RandomCommitMessages[totalCommits%len(RandomCommitMessages)]
self.SetAuthor(author, "")

View File

@ -44,7 +44,7 @@ func (self *ViewDriver) Clear() *ViewDriver {
// clearing multiple times in case there's multiple lines
// (the clear button only clears a single line at a time)
maxAttempts := 100
for i := 0; i < maxAttempts+1; i++ {
for i := range maxAttempts + 1 {
if self.getView().Buffer() == "" {
break
}
@ -104,7 +104,7 @@ func (self *ViewDriver) ContainsLines(matchers ...*TextMatcher) *ViewDriver {
startIdx, endIdx := self.getSelectedRange()
for i := 0; i < len(lines)-len(matchers)+1; i++ {
for i := range len(lines) - len(matchers) + 1 {
matches := true
for j, matcher := range matchers {
checkIsSelected, matcher := matcher.checkIsSelected() // strip the IsSelected matcher out
@ -375,11 +375,11 @@ func (self *ViewDriver) Focus() *ViewDriver {
currentViewName := self.t.gui.CurrentContext().GetViewName()
currentViewTabIndex := lo.IndexOf(window.viewNames, currentViewName)
if tabIndex > currentViewTabIndex {
for i := 0; i < tabIndex-currentViewTabIndex; i++ {
for range tabIndex - currentViewTabIndex {
self.t.press(self.t.keys.Universal.NextTab)
}
} else if tabIndex < currentViewTabIndex {
for i := 0; i < currentViewTabIndex-tabIndex; i++ {
for range currentViewTabIndex - tabIndex {
self.t.press(self.t.keys.Universal.PrevTab)
}
}
@ -534,7 +534,7 @@ func (self *ViewDriver) NavigateToLine(matcher *TextMatcher) *ViewDriver {
keyPress = func() { self.SelectPreviousItem() }
}
for i := 0; i < maxNumKeyPresses; i++ {
for range maxNumKeyPresses {
keyPress()
idx := self.getSelectedLineIdx()
// It is important to use view.BufferLines() here and not lines, because it

View File

@ -18,7 +18,7 @@ func commonSetup(shell *Shell) {
repoStartDaysAgo := 100
for _, authorInfo := range authors {
for i := 0; i < authorInfo.numberOfCommits; i++ {
for i := range authorInfo.numberOfCommits {
authorEmail := strings.ToLower(strings.ReplaceAll(authorInfo.name, " ", ".")) + "@email.com"
commitMessage := fmt.Sprintf("commit %d", i)

View File

@ -114,7 +114,7 @@ func setDefaultVals(rootSchema, schema *jsonschema.Schema, defaults any) {
return
}
for i := 0; i < t.NumField(); i++ {
for i := range t.NumField() {
value := v.Field(i).Interface()
parentKey := t.Field(i).Name
@ -152,7 +152,7 @@ func isZeroValue(v any) bool {
case reflect.Ptr, reflect.Interface:
return rv.IsNil()
case reflect.Struct:
for i := 0; i < rv.NumField(); i++ {
for i := range rv.NumField() {
if !isZeroValue(rv.Field(i).Interface()) {
return false
}

View File

@ -129,7 +129,7 @@ func (self *Game) newFoodPos(snakePositions []Position) Position {
// arbitrarily setting a limit of attempts to place food
attemptLimit := 1000
for i := 0; i < attemptLimit; i++ {
for range attemptLimit {
newFoodPos := Position{self.randIntFn(self.width), self.randIntFn(self.height)}
if !lo.Contains(snakePositions, newFoodPos) {
@ -183,7 +183,7 @@ func (self *Game) getCells(state State) [][]CellType {
cells[pos.y][pos.x] = value
}
for i := 0; i < self.height; i++ {
for i := range self.height {
cells[i] = make([]CellType, self.width)
}

View File

@ -25,7 +25,7 @@ type ColumnConfig struct {
func StringWidth(s string) int {
// We are intentionally not using a range loop here, because that would
// convert the characters to runes, which is unnecessary work in this case.
for i := 0; i < len(s); i++ {
for i := range len(s) {
if s[i] > unicode.MaxASCII {
return runewidth.StringWidth(s)
}

View File

@ -41,7 +41,7 @@ func FindSubstringsFrom(pattern string, data fuzzy.Source) fuzzy.Matches {
result := fuzzy.Matches{}
outer:
for i := 0; i < data.Len(); i++ {
for i := range data.Len() {
s := data.String(i)
for _, sub := range substrings {
if !CaseAwareContains(s, sub) {

View File

@ -48,12 +48,12 @@ func TestThreadSafeMapConcurrentReadWrite(t *testing.T) {
m := NewThreadSafeMap[int, int]()
go func() {
for i := 0; i < 10000; i++ {
for range 10000 {
m.Set(0, 0)
}
}()
for i := 0; i < 10000; i++ {
for range 10000 {
m.Get(0)
}
}

View File

@ -139,7 +139,7 @@ func walk(node *yaml.Node, path string, callback func(*yaml.Node, string)) error
}
}
case yaml.SequenceNode:
for i := 0; i < len(node.Content); i++ {
for i := range len(node.Content) {
childPath := fmt.Sprintf("%s[%d]", path, i)
err := walk(node.Content[i], childPath, callback)
if err != nil {