Skip to content

Commit 4f290e0

Browse files
authored
chore: add support for intrange (#4048)
1 parent 44f37c5 commit 4f290e0

File tree

15 files changed

+36
-35
lines changed

15 files changed

+36
-35
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ linters:
2727
- govet #(vet, vetshadow): Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false]
2828
- importas # Enforces consistent import aliases [fast: false, auto-fix: false]
2929
- ineffassign # Detects when assignments to existing variables are not used [fast: true, auto-fix: false]
30+
- intrange # intrange is a linter to find places where for loops could make use of an integer range. [fast: true, auto-fix: false]
3031
- misspell # Finds commonly misspelled English words in comments [fast: true, auto-fix: true]
3132
- nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false]
3233
- nolintlint # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false]

internal/args/args.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func GetArgType(argType reflect.Type, name string) (reflect.Type, error) {
225225
// We construct two caches:
226226
anonymousFieldIndexes := []int(nil)
227227
fieldIndexByName := map[string]int{}
228-
for i := 0; i < argType.NumField(); i++ {
228+
for i := range argType.NumField() {
229229
field := argType.Field(i)
230230
if field.Anonymous {
231231
anonymousFieldIndexes = append(anonymousFieldIndexes, i)
@@ -283,7 +283,7 @@ func listArgTypeFields(base string, argType reflect.Type) []string {
283283
case reflect.Struct:
284284
fields := []string(nil)
285285

286-
for i := 0; i < argType.NumField(); i++ {
286+
for i := range argType.NumField() {
287287
field := argType.Field(i)
288288
fieldBase := base
289289

internal/args/marshal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func marshal(src reflect.Value, keys []string) (args []string, err error) {
140140

141141
// We loop through all items and marshal them with key = key.0, key.1, ....
142142
args := []string(nil)
143-
for i := 0; i < src.Len(); i++ {
143+
for i := range src.Len() {
144144
subArgs, err := marshal(src.Index(i), append(keys, strconv.Itoa(i)))
145145
if err != nil {
146146
return nil, err
@@ -178,7 +178,7 @@ func marshal(src reflect.Value, keys []string) (args []string, err error) {
178178
// If type is a struct
179179
// We loop through all struct field
180180
args := []string(nil)
181-
for i := 0; i < src.NumField(); i++ {
181+
for i := range src.NumField() {
182182
fieldValue := src.Field(i)
183183
key := strcase.ToBashArg(src.Type().Field(i).Name)
184184
newArgs, err := marshal(fieldValue, append(keys, key))

internal/args/unmarshal.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ func set(dest reflect.Value, argNameWords []string, value string) error {
332332
// We construct two caches:
333333
anonymousFieldIndexes := []int(nil)
334334
fieldIndexByName := map[string]int{}
335-
for i := 0; i < dest.Type().NumField(); i++ {
335+
for i := range dest.Type().NumField() {
336336
field := dest.Type().Field(i)
337337
if field.Anonymous {
338338
anonymousFieldIndexes = append(anonymousFieldIndexes, i)

internal/core/autocomplete_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func AutocompleteGetArg(ctx context.Context, cmd *Command, argSpec *ArgSpec, com
170170
}
171171
values := []string(nil)
172172
// Let's iterate over the struct in the response slice and get the searched field
173-
for i := 0; i < resources.Len(); i++ {
173+
for i := range resources.Len() {
174174
resource := resources.Index(i)
175175
if resource.Kind() == reflect.Ptr {
176176
resource = resource.Elem()

internal/core/printer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ func (p *Printer) printTemplate(data interface{}) error {
293293
switch dataValue.Type().Kind() {
294294
// If we have a slice of value, we apply the template for each item
295295
case reflect.Slice:
296-
for i := 0; i < dataValue.Len(); i++ {
296+
for i := range dataValue.Len() {
297297
elemValue := dataValue.Index(i)
298298
err := p.template.Execute(writer, elemValue)
299299
if err != nil {

internal/core/reflect.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import (
1515
// becomes struct{FieldName string `json:"field_name"`}
1616
func newObjectWithForcedJSONTags(t reflect.Type) interface{} {
1717
structFieldsCopy := []reflect.StructField(nil)
18-
for i := 0; i < t.NumField(); i++ {
18+
for i := range t.NumField() {
1919
fieldCopy := t.Field(i)
2020
if fieldCopy.Anonymous {
2121
anonymousType := fieldCopy.Type
2222
if anonymousType.Kind() == reflect.Ptr {
2323
anonymousType = anonymousType.Elem()
2424
}
25-
for i := 0; i < anonymousType.NumField(); i++ {
25+
for i := range anonymousType.NumField() {
2626
fieldCopy := anonymousType.Field(i)
2727
fieldCopy.Tag = reflect.StructTag(`json:"` + strings.ReplaceAll(strcase.ToBashArg(fieldCopy.Name), "-", "_") + `"`)
2828
structFieldsCopy = append(structFieldsCopy, fieldCopy)
@@ -49,7 +49,7 @@ func GetValuesForFieldByName(value reflect.Value, parts []string) (values []refl
4949
values := []reflect.Value(nil)
5050
errs := []error(nil)
5151

52-
for i := 0; i < value.Len(); i++ {
52+
for i := range value.Len() {
5353
newValues, err := GetValuesForFieldByName(value.Index(i), parts[1:])
5454
if err != nil {
5555
errs = append(errs, err)
@@ -90,7 +90,7 @@ func GetValuesForFieldByName(value reflect.Value, parts []string) (values []refl
9090
anonymousFieldIndexes := []int(nil)
9191
fieldIndexByName := map[string]int{}
9292

93-
for i := 0; i < value.NumField(); i++ {
93+
for i := range value.NumField() {
9494
field := value.Type().Field(i)
9595
if field.Anonymous {
9696
anonymousFieldIndexes = append(anonymousFieldIndexes, i)

internal/e2e/sdk_errors_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestSdkStandardErrors(t *testing.T) {
3333
UseE2EClient: true,
3434
DisableParallel: true, // because e2e client is used
3535
BeforeFunc: func(ctx *core.BeforeFuncCtx) error {
36-
for i := 0; i < 10; i++ {
36+
for range 10 {
3737
ctx.ExecuteCmd([]string{"scw", "test", "human", "create"})
3838
}
3939
return nil

internal/editor/reflect.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func hasTag(tags []string, actualTag string) bool {
4545
func valueMapperWithoutOpt(dest reflect.Value, src reflect.Value, includeFields []string, excludeFields []string) {
4646
switch dest.Kind() {
4747
case reflect.Struct:
48-
for i := 0; i < dest.NumField(); i++ {
48+
for i := range dest.NumField() {
4949
destField := dest.Field(i)
5050
fieldType := dest.Type().Field(i)
5151
srcField := src.FieldByName(fieldType.Name)
@@ -82,7 +82,7 @@ func valueMapperWithoutOpt(dest reflect.Value, src reflect.Value, includeFields
8282
// If destination is a slice, allocate the slice and map each value
8383
srcLen := src.Len()
8484
dest.Set(reflect.MakeSlice(dest.Type(), srcLen, srcLen))
85-
for i := 0; i < srcLen; i++ {
85+
for i := range srcLen {
8686
valueMapperWithoutOpt(dest.Index(i), src.Index(i), includeFields, excludeFields)
8787
}
8888
default:
@@ -140,7 +140,7 @@ func DeleteRecursive(elem interface{}, keys ...string) {
140140
case reflect.Map:
141141
deleteRecursiveMap(elem.(map[string]interface{}), keys...)
142142
case reflect.Slice:
143-
for i := 0; i < value.Len(); i++ {
143+
for i := range value.Len() {
144144
DeleteRecursive(value.Index(i).Interface(), keys...)
145145
}
146146
}

internal/gofields/gofields.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func listFields(t reflect.Type, parents []string, filter ListFieldFilter) []stri
136136
return listFields(t.Elem(), append(parents, "<key>"), filter)
137137
case reflect.Struct:
138138
res := []string(nil)
139-
for i := 0; i < t.NumField(); i++ {
139+
for i := range t.NumField() {
140140
field := t.Field(i)
141141

142142
if !isFieldPublic(field) {

0 commit comments

Comments
 (0)