convert/conv.go
File conv.go
has 546 lines of code (exceeds 500 allowed). Consider refactoring. Open
Open
// Package convert provides functions for converting data and functions between Go and Starlark.
package convert
import (
"errors"
Function toValue
has 64 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func toValue(val reflect.Value, tagName string) (result starlark.Value, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("panic recovered: %v", r)
}
Avoid deeply nested control flow statements. Open
Open
if unwrapped.Type().ConvertibleTo(targetType) {
return unwrapped.Convert(targetType), nil
} else if sv, ok := unwrapped.Interface().(starlark.Value); ok {
// TODO: this path is not reachable in the current test, maybe we can remove it?
goVal := FromValue(sv)
Function convertElemValue
has 7 return statements (exceeds 4 allowed). Open
Open
func convertElemValue(val reflect.Value, targetType reflect.Type) (reflect.Value, error) {
if val.Type().AssignableTo(targetType) || val.Type().ConvertibleTo(targetType) {
return val.Convert(targetType), nil
} else if val.Kind() == reflect.Ptr || val.Kind() == reflect.Interface {
if val.IsNil() {
Function toValue
has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring. Open
Open
func toValue(val reflect.Value, tagName string) (result starlark.Value, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("panic recovered: %v", r)
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function convertReflectValue
has 6 return statements (exceeds 4 allowed). Open
Open
func convertReflectValue(val reflect.Value, argT reflect.Type) (reflect.Value, error) {
if !val.IsValid() {
return reflect.Zero(argT), nil
}
if val.Type().AssignableTo(argT) {
Function makeOut
has 6 return statements (exceeds 4 allowed). Open
Open
func makeOut(out []reflect.Value, tagName string) (starlark.Value, error) {
if len(out) == 0 {
return starlark.None, nil
}
last := out[len(out)-1]
Function toValue
has 5 return statements (exceeds 4 allowed). Open
Open
func toValue(val reflect.Value, tagName string) (result starlark.Value, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("panic recovered: %v", r)
}