Skip to content

Commit ed38fd1

Browse files
committed
Swap go code to use the 'range N' syntax added in go 1.22
1 parent 3f34db5 commit ed38fd1

File tree

5 files changed

+10
-11
lines changed

5 files changed

+10
-11
lines changed

backend/server/internal/release/release.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func BuildUpdateInfo(version string) shared.UpdateInfo {
6767
func decrementVersionIfInvalid(initialVersion string) string {
6868
// Decrements the version up to 5 times if the version doesn't have valid binaries yet.
6969
version := initialVersion
70-
for i := 0; i < 5; i++ {
70+
for range 5 {
7171
updateInfo := BuildUpdateInfo(version)
7272
err := assertValidUpdate(updateInfo)
7373
if err == nil {

client/integration_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ func testRepeatedCommandThenQuery(t *testing.T, tester shellTester) {
648648
}
649649

650650
// Run a command many times
651-
for i := 0; i < 25; i++ {
651+
for i := range 25 {
652652
tester.RunInteractiveShell(t, fmt.Sprintf("echo mycommand-%d", i))
653653
}
654654

@@ -688,7 +688,7 @@ func testRepeatedCommandAndQuery(t *testing.T, tester shellTester) {
688688
}
689689

690690
// Run a command many times
691-
for i := 0; i < 25; i++ {
691+
for i := range 25 {
692692
tester.RunInteractiveShell(t, fmt.Sprintf("echo mycommand-%d", i))
693693
out = hishtoryQuery(t, tester, fmt.Sprintf("mycommand-%d", i))
694694
if strings.Count(out, "\n") != 3 {
@@ -707,7 +707,7 @@ func testRepeatedEnableDisable(t *testing.T, tester shellTester) {
707707
installHishtory(t, tester, "")
708708

709709
// Run a command many times
710-
for i := 0; i < 25; i++ {
710+
for i := range 25 {
711711
tester.RunInteractiveShell(t, fmt.Sprintf(`echo mycommand-%d
712712
hishtory disable
713713
echo shouldnotshowup
@@ -767,7 +767,7 @@ echo hello2
767767
func waitForBackgroundSavesToComplete(t testing.TB) {
768768
lastOut := ""
769769
lastErr := ""
770-
for i := 0; i < 20; i++ {
770+
for range 20 {
771771
cmd := exec.Command(getPidofCommand(), "hishtory")
772772
var stdout bytes.Buffer
773773
var stderr bytes.Buffer
@@ -2942,7 +2942,7 @@ func TestSetConfigNoCorruption(t *testing.T) {
29422942
conf, err := hctx.GetConfig()
29432943
require.NoError(t, err)
29442944
var doneWg sync.WaitGroup
2945-
for i := 0; i < 10; i++ {
2945+
for i := range 10 {
29462946
doneWg.Add(1)
29472947
go func(i int) {
29482948
// Make a new config of a varied length

client/lib/lib.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ func splitEscaped(query string, separator rune, maxSplit int) []string {
10651065
runeQuery := []rune(query)
10661066
isInDoubleQuotedString := false
10671067
isInSingleQuotedString := false
1068-
for i := 0; i < len(runeQuery); i++ {
1068+
for i := range len(runeQuery) {
10691069
if (maxSplit < 0 || splits < maxSplit) && runeQuery[i] == separator && !isInSingleQuotedString && !isInDoubleQuotedString {
10701070
if string(token) != "" {
10711071
tokens = append(tokens, string(token))
@@ -1120,7 +1120,7 @@ func heuristicIgnoreUnclosedQuote(isCurrentlyInQuotedString bool, quoteType rune
11201120

11211121
func containsUnescaped(query, token string) bool {
11221122
runeQuery := []rune(query)
1123-
for i := 0; i < len(runeQuery); i++ {
1123+
for i := range len(runeQuery) {
11241124
if runeQuery[i] == '\\' && i+1 < len(runeQuery) {
11251125
i++
11261126
} else if string(runeQuery[i:i+len(token)]) == token {

client/tui/tui.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ func getRows(ctx context.Context, columnNames []string, shellName, defaultFilter
530530
var filteredData []*data.HistoryEntry
531531
seenCommands := make(map[string]bool)
532532

533-
for i := 0; i < numEntries; i++ {
533+
for i := range numEntries {
534534
if i < len(searchResults) {
535535
entry := searchResults[i]
536536

@@ -1011,5 +1011,4 @@ func TuiQuery(ctx context.Context, shellName string, initialQueryArray []string)
10111011
return nil
10121012
}
10131013

1014-
// TODO: support custom key bindings
10151014
// TODO: make the help page wrap

shared/testutils/testutils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func checkError(err error) {
214214
}
215215

216216
func buildServer() string {
217-
for i := 0; i < 100; i++ {
217+
for range 100 {
218218
wd, err := os.Getwd()
219219
if err != nil {
220220
panic(fmt.Sprintf("failed to getwd: %v", err))

0 commit comments

Comments
 (0)