From c88a8bf424b430c5e69c2722e6182b58aecc7467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Tue, 12 May 2026 16:59:56 +0200 Subject: [PATCH] chore: bump golangci-lint to v2.12.2 --- .github/workflows/lint.yml | 2 +- .golangci.yml | 3 +-- core/autocomplete_utils.go | 2 +- core/human/marshal.go | 10 +++++----- core/human/marshal_func.go | 4 ++-- core/human/utils.go | 2 +- core/reflect.go | 4 ++-- internal/args/args.go | 10 +++++----- internal/args/marshal.go | 6 +++--- internal/args/unmarshal.go | 13 +++++++------ internal/gofields/gofields.go | 8 ++++---- 11 files changed, 32 insertions(+), 32 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6a467c4904..679acf2623 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -39,7 +39,7 @@ jobs: uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0 with: # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v2.9.0 + version: v2.12.2 args: --timeout 10m spelling: diff --git a/.golangci.yml b/.golangci.yml index 9771ff5fc4..5d08fcb6de 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -38,12 +38,11 @@ linters: - funcorder # Checks the order of functions, methods, and constructors. [fast] - gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid. [fast: true, auto-fix: false] - gochecksumtype # Run exhaustiveness checks on Go "sum types" [fast: false, auto-fix: false] - - goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false] - gocritic # Provides diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: false] - gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false] - goheader # Checks is file header matches to pattern [fast: true, auto-fix: false] - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false] - - gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. [fast: true, auto-fix: false] + - gomodguard_v2 # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. [fast: true, auto-fix: false] - goprintffuncname # Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false] - 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] - grouper # An analyzer to analyze expression groups. [fast: true, auto-fix: false] diff --git a/core/autocomplete_utils.go b/core/autocomplete_utils.go index 273050562a..9c990cf3d1 100644 --- a/core/autocomplete_utils.go +++ b/core/autocomplete_utils.go @@ -178,7 +178,7 @@ func AutocompleteGetArg( // Let's iterate over the struct in the response slice and get the searched field for i := range resources.Len() { resource := resources.Index(i) - if resource.Kind() == reflect.Ptr { + if resource.Kind() == reflect.Pointer { resource = resource.Elem() } resourceField := resource.FieldByName(strcase.ToPublicGoName(argName)) diff --git a/core/human/marshal.go b/core/human/marshal.go index 6904442808..2f33dafb6b 100644 --- a/core/human/marshal.go +++ b/core/human/marshal.go @@ -80,7 +80,7 @@ func Marshal(data any, opt *MarshalOpt) (string, error) { return rValue.Interface().(fmt.Stringer).String(), nil // If data is a pointer dereference an call Marshal again - case rType.Kind() == reflect.Ptr: + case rType.Kind() == reflect.Pointer: return Marshal(rValue.Elem().Interface(), opt) // If data is a slice uses marshalSlice @@ -148,7 +148,7 @@ func marshalStruct(value reflect.Value, opt *MarshalOpt) (string, error) { {strings.Join(keys, "."), value.Interface().(fmt.Stringer).String()}, }, nil - case rType.Kind() == reflect.Ptr: + case rType.Kind() == reflect.Pointer: // If type is a pointer we Marshal pointer.Elem() return marshal(value.Elem(), keys) @@ -248,7 +248,7 @@ func GetStructFieldsIndex(v reflect.Type) [][]int { var recFunc func(v reflect.Type, parent []int) recFunc = func(v reflect.Type, parent []int) { - for v.Kind() == reflect.Ptr { + for v.Kind() == reflect.Pointer { v = v.Elem() } @@ -288,7 +288,7 @@ func GetStructFieldsIndex(v reflect.Type) [][]int { func marshalSlice(slice reflect.Value, opt *MarshalOpt) (string, error) { // Resole itemType and get rid of all pointer level if needed. itemType := slice.Type().Elem() - for itemType.Kind() == reflect.Ptr { + for itemType.Kind() == reflect.Pointer { itemType = itemType.Elem() } @@ -378,7 +378,7 @@ func marshalInlineSlice(slice reflect.Value) (string, error) { } itemType := slice.Type().Elem() - for itemType.Kind() == reflect.Ptr { + for itemType.Kind() == reflect.Pointer { itemType = itemType.Elem() } diff --git a/core/human/marshal_func.go b/core/human/marshal_func.go index d230ac0a16..6bbe41f891 100644 --- a/core/human/marshal_func.go +++ b/core/human/marshal_func.go @@ -230,12 +230,12 @@ func defaultMarshalerFunc(i any, _ *MarshalOpt) (string, error) { func isMarshalable(t reflect.Type) bool { _, hasMarshalerFunc := getMarshalerFunc(t) - return (t.Kind() != reflect.Struct && t.Kind() != reflect.Map && t.Kind() != reflect.Ptr) || + return (t.Kind() != reflect.Struct && t.Kind() != reflect.Map && t.Kind() != reflect.Pointer) || hasMarshalerFunc || t.Implements(reflect.TypeOf((*Marshaler)(nil)).Elem()) || t.Implements(reflect.TypeOf((*error)(nil)).Elem()) || t.Implements(reflect.TypeOf((*fmt.Stringer)(nil)).Elem()) || - (t.Kind() == reflect.Ptr && isMarshalable(t.Elem())) + (t.Kind() == reflect.Pointer && isMarshalable(t.Elem())) } // EnumMarshalSpec contains specs used by EnumMarshalFunc. diff --git a/core/human/utils.go b/core/human/utils.go index 0f66ab44fb..8e0d671c76 100644 --- a/core/human/utils.go +++ b/core/human/utils.go @@ -29,7 +29,7 @@ func isInterfaceNil(data any) bool { value := reflect.ValueOf(data) switch value.Kind() { - case reflect.Ptr, reflect.Slice, reflect.Map: + case reflect.Pointer, reflect.Slice, reflect.Map: return value.IsNil() default: return false diff --git a/core/reflect.go b/core/reflect.go index ac98e88b5b..0398b573f7 100644 --- a/core/reflect.go +++ b/core/reflect.go @@ -18,7 +18,7 @@ func newObjectWithForcedJSONTags(t reflect.Type) any { for fieldCopy := range t.Fields() { if fieldCopy.Anonymous { anonymousType := fieldCopy.Type - if anonymousType.Kind() == reflect.Ptr { + if anonymousType.Kind() == reflect.Pointer { anonymousType = anonymousType.Elem() } for field := range anonymousType.Fields() { @@ -52,7 +52,7 @@ func GetValuesForFieldByName( return []reflect.Value{value}, nil } switch value.Kind() { - case reflect.Ptr: + case reflect.Pointer: return GetValuesForFieldByName(value.Elem(), parts) case reflect.Slice: diff --git a/internal/args/args.go b/internal/args/args.go index 4756f3e6f7..f5a70e1af7 100644 --- a/internal/args/args.go +++ b/internal/args/args.go @@ -219,7 +219,7 @@ func GetArgType(argType reflect.Type, name string) (reflect.Type, error) { var recursiveFunc func(argType reflect.Type, parts []string) (reflect.Type, error) recursiveFunc = func(argType reflect.Type, parts []string) (reflect.Type, error) { switch { - case argType.Kind() == reflect.Ptr: + case argType.Kind() == reflect.Pointer: return recursiveFunc(argType.Elem(), parts) case len(parts) == 0: return argType, nil @@ -254,8 +254,8 @@ func GetArgType(argType reflect.Type, name string) (reflect.Type, error) { } // If it does not exist we try to find it in nested anonymous field - for i := len(anonymousFieldIndexes) - 1; i >= 0; i-- { - argType, err := recursiveFunc(argType.Field(anonymousFieldIndexes[i]).Type, parts) + for _, v := range slices.Backward(anonymousFieldIndexes) { + argType, err := recursiveFunc(argType.Field(v).Type, parts) if err == nil { return argType, nil } @@ -275,7 +275,7 @@ var listArgTypeFieldsSkippedArguments = []string{ } func listArgTypeFields(base string, argType reflect.Type) []string { - if argType.Kind() != reflect.Ptr { + if argType.Kind() != reflect.Pointer { // Can be a handled type like time.Time // If so, use it like a scalar type _, isHandled := unmarshalFuncs[argType] @@ -285,7 +285,7 @@ func listArgTypeFields(base string, argType reflect.Type) []string { } switch argType.Kind() { - case reflect.Ptr: + case reflect.Pointer: return listArgTypeFields(base, argType.Elem()) case reflect.Slice: diff --git a/internal/args/marshal.go b/internal/args/marshal.go index a472a6d520..fc3b04f91c 100644 --- a/internal/args/marshal.go +++ b/internal/args/marshal.go @@ -50,7 +50,7 @@ func MarshalStruct(data any) (args []string, err error) { // Second make sure data is a pointer to a struct or a map. src := reflect.ValueOf(data) - if !(src.Kind() == reflect.Ptr && (src.Elem().Kind() == reflect.Struct || src.Elem().Kind() == reflect.Map)) { + if !(src.Kind() == reflect.Pointer && (src.Elem().Kind() == reflect.Struct || src.Elem().Kind() == reflect.Map)) { return nil, &DataMustBeAPointerError{} } @@ -121,7 +121,7 @@ func marshal(src reflect.Value, keys []string) (args []string, err error) { } switch src.Kind() { - case reflect.Ptr: + case reflect.Pointer: // If src is nil we do not marshal it if src.IsNil() { return nil, nil @@ -288,7 +288,7 @@ func isInterfaceNil(data any) bool { value := reflect.ValueOf(data) switch value.Kind() { - case reflect.Ptr, reflect.Slice, reflect.Map: + case reflect.Pointer, reflect.Slice, reflect.Map: return value.IsNil() default: return false diff --git a/internal/args/unmarshal.go b/internal/args/unmarshal.go index 552a264431..49b2317ccf 100644 --- a/internal/args/unmarshal.go +++ b/internal/args/unmarshal.go @@ -10,6 +10,7 @@ import ( "io" "net" "reflect" + "slices" "strconv" "strings" "time" @@ -150,7 +151,7 @@ func UnmarshalStruct(args []string, data any) error { // Second make sure data is a pointer to a struct or a map. dest := reflect.ValueOf(data) - if !(dest.Kind() == reflect.Ptr && (dest.Elem().Kind() == reflect.Struct || dest.Elem().Kind() == reflect.Map)) { + if !(dest.Kind() == reflect.Pointer && (dest.Elem().Kind() == reflect.Struct || dest.Elem().Kind() == reflect.Map)) { return &DataMustBeAPointerError{} } @@ -217,7 +218,7 @@ func IsUmarshalableValue(data any) bool { return false } - for dest.Kind() == reflect.Ptr { + for dest.Kind() == reflect.Pointer { dest = dest.Elem() } @@ -250,7 +251,7 @@ func set(dest reflect.Value, argNameWords []string, value string) error { } } - for dest.Kind() == reflect.Ptr { + for dest.Kind() == reflect.Pointer { dest.Set(reflect.New(dest.Type().Elem())) dest = dest.Elem() } @@ -259,7 +260,7 @@ func set(dest reflect.Value, argNameWords []string, value string) error { } switch dest.Kind() { - case reflect.Ptr: + case reflect.Pointer: // If type is a nil pointer we create a new Value. NB: maps and slices are pointers. if dest.IsNil() { dest.Set(reflect.New(dest.Type().Elem())) @@ -370,8 +371,8 @@ func set(dest reflect.Value, argNameWords []string, value string) error { } // If it does not exist we try to find it in nested anonymous field - for i := len(anonymousFieldIndexes) - 1; i >= 0; i-- { - err := set(dest.Field(anonymousFieldIndexes[i]), argNameWords, value) + for _, v := range slices.Backward(anonymousFieldIndexes) { + err := set(dest.Field(v), argNameWords, value) switch err.(type) { case nil: // If we got no error the field was correctly set we return nil. diff --git a/internal/gofields/gofields.go b/internal/gofields/gofields.go index 456e81a3bf..6002585ccf 100644 --- a/internal/gofields/gofields.go +++ b/internal/gofields/gofields.go @@ -40,7 +40,7 @@ func getValue(value reflect.Value, parents []string, path []string) (reflect.Val return reflect.Value{}, NewNilValueError(strings.Join(parents, ".")) } - if value.Type().Kind() == reflect.Ptr { + if value.Type().Kind() == reflect.Pointer { return getValue(value.Elem(), parents, path) } @@ -113,7 +113,7 @@ func getType(t reflect.Type, parents []string, path []string) (reflect.Type, err return t, nil } - if t.Kind() == reflect.Ptr { + if t.Kind() == reflect.Pointer { return getType(t.Elem(), parents, path) } @@ -167,7 +167,7 @@ func ListFieldsWithFilter(t reflect.Type, filter ListFieldFilter) []string { } func listFields(t reflect.Type, parents []string, filter ListFieldFilter) []string { - if t.Kind() == reflect.Ptr { + if t.Kind() == reflect.Pointer { return listFields(t.Elem(), parents, filter) } @@ -204,7 +204,7 @@ func listFields(t reflect.Type, parents []string, filter ListFieldFilter) []stri // IsNil test if a given value is nil. It is saf to call the method with non nillable value like scalar types func IsNil(value reflect.Value) bool { - return (value.Kind() == reflect.Ptr || value.Kind() == reflect.Slice || value.Kind() == reflect.Map) && + return (value.Kind() == reflect.Pointer || value.Kind() == reflect.Slice || value.Kind() == reflect.Map) && value.IsNil() }