Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Comment on lines 38 to 46
- 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]
Expand Down
2 changes: 1 addition & 1 deletion core/autocomplete_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 5 additions & 5 deletions core/human/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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()
}

Expand Down
4 changes: 2 additions & 2 deletions core/human/marshal_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion core/human/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions internal/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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]
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions internal/args/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions internal/args/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"net"
"reflect"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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{}
}

Expand Down Expand Up @@ -217,7 +218,7 @@ func IsUmarshalableValue(data any) bool {
return false
}

for dest.Kind() == reflect.Ptr {
for dest.Kind() == reflect.Pointer {
dest = dest.Elem()
}

Expand Down Expand Up @@ -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()
}
Expand All @@ -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()))
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions internal/gofields/gofields.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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()
}

Expand Down
Loading