1set/starlight

View on GitHub

Showing 95 of 95 total issues

File conv.go has 546 lines of code (exceeds 500 allowed). Consider refactoring.
Open

// Package convert provides functions for converting data and functions between Go and Starlark.
package convert

import (
    "errors"
Severity: Minor
Found in convert/conv.go - About 3 hrs to fix

    Function updateDict has a Cognitive Complexity of 32 (exceeds 20 allowed). Consider refactoring.
    Open

    func updateDict(dict *GoMap, updates starlark.Tuple, kwargs []starlark.Tuple) error {
        if len(updates) == 1 {
            switch updates := updates[0].(type) {
            case starlark.NoneType:
                // no-op
    Severity: Minor
    Found in convert/map.go - About 2 hrs to fix

    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

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    func sliceAttr(g *GoSlice, name string, methods map[string]builtinSliceMethod) (starlark.Value, error) {
        method := methods[name]
        if method == nil {
            return nil, nil // no such method
        }
    Severity: Major
    Found in convert/slice.go and 1 other location - About 1 hr to fix
    convert/map.go on lines 227..238

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 173.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

    func mapAttr(recv *GoMap, name string, methods map[string]builtinMapMethod) (starlark.Value, error) {
        method := methods[name]
        if method == nil {
            return nil, nil // no such method
        }
    Severity: Major
    Found in convert/map.go and 1 other location - About 1 hr to fix
    convert/slice.go on lines 160..171

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 173.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function toValue has 64 lines of code (exceeds 50 allowed). Consider refactoring.
    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)
            }
    Severity: Minor
    Found in convert/conv.go - About 1 hr to fix

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      func (g *GoInterface) ToUint() (uint64, error) {
          v := g.v
          if v.Kind() == reflect.Ptr {
              v = v.Elem()
          }
      Severity: Major
      Found in convert/interface.go and 1 other location - About 1 hr to fix
      convert/interface.go on lines 149..159

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 143.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      func (g *GoInterface) ToInt() (int64, error) {
          v := g.v
          if v.Kind() == reflect.Ptr {
              v = v.Elem()
          }
      Severity: Major
      Found in convert/interface.go and 1 other location - About 1 hr to fix
      convert/interface.go on lines 177..187

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 143.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Function updateDict has 8 return statements (exceeds 4 allowed).
      Open

      func updateDict(dict *GoMap, updates starlark.Tuple, kwargs []starlark.Tuple) error {
          if len(updates) == 1 {
              switch updates := updates[0].(type) {
              case starlark.NoneType:
                  // no-op
      Severity: Major
      Found in convert/map.go - About 50 mins to fix

        Avoid deeply nested control flow statements.
        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)
        Severity: Major
        Found in convert/conv.go - About 45 mins to fix

          Function convertElemValue has 7 return statements (exceeds 4 allowed).
          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() {
          Severity: Major
          Found in convert/conv.go - About 45 mins to fix

            Function toValue has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
            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)
                    }
            Severity: Minor
            Found in convert/conv.go - About 45 mins to fix

            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

            Avoid deeply nested control flow statements.
            Open

                            } else if l != 2 {
                                return fmt.Errorf("dictionary update sequence element #%d has length %d, want 2", i, l)
                            }
            Severity: Major
            Found in convert/map.go - About 45 mins to fix

              Function convertReflectValue has 6 return statements (exceeds 4 allowed).
              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) {
              Severity: Major
              Found in convert/conv.go - About 40 mins to fix

                Function makeOut has 6 return statements (exceeds 4 allowed).
                Open

                func makeOut(out []reflect.Value, tagName string) (starlark.Value, error) {
                    if len(out) == 0 {
                        return starlark.None, nil
                    }
                    last := out[len(out)-1]
                Severity: Major
                Found in convert/conv.go - About 40 mins to fix

                  Function list_remove has 5 return statements (exceeds 4 allowed).
                  Open

                  func list_remove(fnname string, g *GoSlice, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
                      if len(args) != 1 {
                          return nil, fmt.Errorf("remove: got %d arguments, want 1", len(args))
                      }
                      if err := g.checkMutable("remove from"); err != nil {
                  Severity: Major
                  Found in convert/slice.go - About 35 mins to fix

                    Function toValue has 5 return statements (exceeds 4 allowed).
                    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)
                            }
                    Severity: Major
                    Found in convert/conv.go - About 35 mins to fix

                      Method GoMap.SetKey has 5 return statements (exceeds 4 allowed).
                      Open

                      func (g *GoMap) SetKey(k, v starlark.Value) (err error) {
                          if g.frozen {
                              return fmt.Errorf("cannot insert into frozen map")
                          }
                          if g.numIt > 0 {
                      Severity: Major
                      Found in convert/map.go - About 35 mins to fix

                        Function list_pop has 5 return statements (exceeds 4 allowed).
                        Open

                        func list_pop(fnname string, g *GoSlice, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
                            index := g.v.Len() - 1
                            switch len(args) {
                            case 0:
                                // ok
                        Severity: Major
                        Found in convert/slice.go - About 35 mins to fix

                          Method Cache.Run has 5 return statements (exceeds 4 allowed).
                          Open

                          func (c *Cache) Run(filename string, globals map[string]interface{}) (map[string]interface{}, error) {
                              dict, err := convert.MakeStringDict(globals)
                              if err != nil {
                                  return nil, err
                              }
                          Severity: Major
                          Found in starlight.go - About 35 mins to fix

                            Function dict_pop has 5 return statements (exceeds 4 allowed).
                            Open

                            func dict_pop(fnname string, g *GoMap, args starlark.Tuple, _ []starlark.Tuple) (starlark.Value, error) {
                                if len(args) == 0 || len(args) > 2 {
                                    return nil, fmt.Errorf("%s: got %d arguments, want 1 or 2", fnname, len(args))
                                }
                                v, found, err := g.Delete(args[0])
                            Severity: Major
                            Found in convert/map.go - About 35 mins to fix
                              Severity
                              Category
                              Status
                              Source
                              Language