Skip to content

Commit 0471dba

Browse files
committed
Enable intrange linter, and fix warnings
1 parent 1e92d8b commit 0471dba

File tree

21 files changed

+35
-34
lines changed

21 files changed

+35
-34
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ linters:
55
enable:
66
- copyloopvar
77
- exhaustive
8+
- intrange
89
- makezero
910
- nakedret
1011
- nolintlint

pkg/commands/git_cmd_obj_runner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (self *gitCmdObjRunner) Run(cmdObj *oscommands.CmdObj) error {
2828
func (self *gitCmdObjRunner) RunWithOutput(cmdObj *oscommands.CmdObj) (string, error) {
2929
var output string
3030
var err error
31-
for i := 0; i < RetryCount; i++ {
31+
for range RetryCount {
3232
newCmdObj := cmdObj.Clone()
3333
output, err = self.innerRunner.RunWithOutput(newCmdObj)
3434

@@ -47,7 +47,7 @@ func (self *gitCmdObjRunner) RunWithOutput(cmdObj *oscommands.CmdObj) (string, e
4747
func (self *gitCmdObjRunner) RunWithOutputs(cmdObj *oscommands.CmdObj) (string, string, error) {
4848
var stdout, stderr string
4949
var err error
50-
for i := 0; i < RetryCount; i++ {
50+
for range RetryCount {
5151
newCmdObj := cmdObj.Clone()
5252
stdout, stderr, err = self.innerRunner.RunWithOutputs(newCmdObj)
5353

pkg/commands/oscommands/os.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func (c *OSCommand) PipeCommands(cmdObjs ...*CmdObj) error {
222222

223223
c.LogCommand(logCmdStr, true)
224224

225-
for i := 0; i < len(cmds)-1; i++ {
225+
for i := range len(cmds) - 1 {
226226
stdout, err := cmds[i].StdoutPipe()
227227
if err != nil {
228228
return err

pkg/commands/patch/patch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (self *Patch) HunkStartIdx(hunkIndex int) int {
5656
hunkIndex = lo.Clamp(hunkIndex, 0, len(self.hunks)-1)
5757

5858
result := len(self.header)
59-
for i := 0; i < hunkIndex; i++ {
59+
for i := range hunkIndex {
6060
result += self.hunks[i].lineCount()
6161
}
6262
return result

pkg/commands/patch/patch_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (p *PatchBuilder) addFileWhole(info *fileInfo) {
9191
// add every line index
9292
// TODO: add tests and then use lo.Range to simplify
9393
info.includedLineIndices = make([]int, lineCount)
94-
for i := 0; i < lineCount; i++ {
94+
for i := range lineCount {
9595
info.includedLineIndices[i] = i
9696
}
9797
}

pkg/config/user_config_validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func validateKeybindingsRecurse(path string, node any) error {
5656
}
5757
}
5858
} else if value.Kind() == reflect.Slice {
59-
for i := 0; i < value.Len(); i++ {
59+
for i := range value.Len() {
6060
if err := validateKeybindingsRecurse(
6161
fmt.Sprintf("%s[%d]", path, i), value.Index(i).Interface()); err != nil {
6262
return err

pkg/gui/context/list_renderer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ func TestListRenderer_ModelIndexToViewIndex_and_back(t *testing.T) {
257257
// Need to render first so that it knows the non-model items
258258
self.renderLines(-1, -1)
259259

260-
for i := 0; i < len(s.modelIndices); i++ {
260+
for i := range len(s.modelIndices) {
261261
assert.Equal(t, s.expectedViewIndices[i], self.ModelIndexToViewIndex(s.modelIndices[i]))
262262
}
263263

264-
for i := 0; i < len(s.viewIndices); i++ {
264+
for i := range len(s.viewIndices) {
265265
assert.Equal(t, s.expectedModelIndices[i], self.ViewIndexToModelIndex(s.viewIndices[i]))
266266
}
267267
})

pkg/gui/controllers/workspace_reset_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (self *FilesController) Explode(v *gocui.View, onDone func()) {
180180

181181
self.c.OnWorker(func(_ gocui.Task) error {
182182
max := 25
183-
for i := 0; i < max; i++ {
183+
for i := range max {
184184
image := getExplodeImage(width, height, i, max)
185185
style := styles[(i*len(styles)/max)%len(styles)]
186186
coloredImage := style.Sprint(image)
@@ -229,8 +229,8 @@ func getExplodeImage(width int, height int, frame int, max int) string {
229229
innerRadius = (progress - 0.5) * 2 * maxRadius
230230
}
231231

232-
for y := 0; y < height; y++ {
233-
for x := 0; x < width; x++ {
232+
for y := range height {
233+
for x := range width {
234234
// calculate distance from center, scale x by 2 to compensate for character aspect ratio
235235
distance := math.Hypot(float64(x-centerX), float64(y-centerY)*2)
236236

pkg/gui/presentation/graph/graph.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func RenderAux(pipeSets [][]Pipe, commits []*models.Commit, selectedCommitHashPt
7979
wg := sync.WaitGroup{}
8080
wg.Add(maxProcs)
8181

82-
for i := 0; i < maxProcs; i++ {
82+
for i := range maxProcs {
8383
go func() {
8484
from := i * perProc
8585
to := (i + 1) * perProc

pkg/gui/presentation/graph/graph_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ func generateCommits(hashPool *utils.StringPool, count int) []*models.Commit {
579579
parentCount := rnd.Intn(2) + 1
580580

581581
parentHashes := currentCommit.Parents()
582-
for j := 0; j < parentCount; j++ {
582+
for j := range parentCount {
583583
reuseParent := rnd.Intn(6) != 1 && j <= len(pool)-1 && j != 0
584584
var newParent *models.Commit
585585
if reuseParent {

0 commit comments

Comments
 (0)