1set/starlet

View on GitHub

Showing 51 of 84 total issues

Function setBody has 11 return statements (exceeds 4 allowed).
Open

func setBody(req *http.Request, body *types.NullableStringOrBytes, formData *starlark.Dict, formEncoding starlark.String, jsonData starlark.Value) error {
    if !body.IsNullOrEmpty() {
        uq := body.GoString()
        req.Body = ioutil.NopCloser(strings.NewReader(uq))
        // Specifying the Content-Length ensures that https://go.dev/src/net/http/transfer.go doesnt specify Transfer-Encoding: chunked which is not supported by some endpoints.
Severity: Major
Found in lib/http/http.go - About 1 hr to fix

    Function copyFileGo has 11 return statements (exceeds 4 allowed).
    Open

    func copyFileGo(src, dst string, overwrite bool) (string, error) {
        // No empty input
        if src == emptyStr {
            return emptyStr, errors.New("source path is empty")
        }
    Severity: Major
    Found in lib/file/copy.go - About 1 hr to fix

      Method Machine.prepareThread has 10 return statements (exceeds 4 allowed).
      Open

      func (m *Machine) prepareThread(extras StringAnyMap) (err error) {
          mergeExtra := func() error {
              // no extras
              if extras == nil {
                  return nil
      Severity: Major
      Found in run.go - About 1 hr to fix

        Function writeDict has 9 return statements (exceeds 4 allowed).
        Open

        func writeDict(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
            var (
                buf    = &bytes.Buffer{}
                data   starlark.Value
                header starlark.Iterable
        Severity: Major
        Found in lib/csv/csv.go - About 55 mins to fix

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

          func Marshal(data interface{}) (v starlark.Value, err error) {
              switch x := data.(type) {
              case nil:
                  v = starlark.None
              case bool:
          Severity: Major
          Found in dataconv/marshal.go - About 50 mins to fix

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

            func shuffle(thread *starlark.Thread, bn *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
                // precondition checks
                var seq starlark.HasSetIndex
                if err := starlark.UnpackArgs(bn.Name(), args, kwargs, "seq", &seq); err != nil {
                    return nil, err
            Severity: Major
            Found in lib/random/random.go - About 50 mins to fix

              Function ExecModuleWithErrorTest has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              func ExecModuleWithErrorTest(t *testing.T, name string, loader ModuleLoadFunc, script string, wantErr string, predecl starlark.StringDict) (starlark.StringDict, error) {
              Severity: Minor
              Found in internal/testloader.go - About 45 mins to fix

                Function setQueryParams has 7 return statements (exceeds 4 allowed).
                Open

                func setQueryParams(rawurl *string, params *starlark.Dict) error {
                    keys := params.Keys()
                    if len(keys) == 0 {
                        return nil
                    }
                Severity: Major
                Found in lib/http/http.go - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                      } else if sm, ok := m.(*starlarkstruct.Struct); ok && sm != nil {
                                          sd := make(starlark.StringDict)
                                          sm.ToStringDict(sd)
                                          return sd, nil
                                      }
                  Severity: Major
                  Found in internal/testloader.go - About 45 mins to fix

                    Function processArgs has 7 return statements (exceeds 4 allowed).
                    Open

                    func processArgs() int {
                        // get starlet machine
                        mac := starlet.NewWithNames(nil, preloadModules, lazyLoadModules)
                        if allowRecursion {
                            mac.EnableRecursionSupport()
                    Severity: Major
                    Found in cmd/starlet/main.go - About 45 mins to fix

                      Function writeAll has 7 return statements (exceeds 4 allowed).
                      Open

                      func writeAll(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
                          var (
                              buf   = &bytes.Buffer{}
                              data  starlark.Value
                              comma string
                      Severity: Major
                      Found in lib/csv/csv.go - About 45 mins to fix

                        Method Module.reqMethod has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
                        Open

                        func (m *Module) reqMethod(method string) func(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
                            return func(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
                                var (
                                    getDefaultDict = func() *types.NullableDict { return types.NewNullableDict(starlark.NewDict(0)) }
                                    urlv           starlark.String
                        Severity: Minor
                        Found in lib/http/http.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

                        Method Machine.Call has 7 return statements (exceeds 4 allowed).
                        Open

                        func (m *Machine) Call(name string, args ...interface{}) (out interface{}, err error) {
                            m.mu.Lock()
                            defer m.mu.Unlock()
                        
                            defer func() {
                        Severity: Major
                        Found in call.go - About 45 mins to fix

                          Function TypeConvert has 7 return statements (exceeds 4 allowed).
                          Open

                          func TypeConvert(data interface{}) interface{} {
                              switch v := data.(type) {
                              case string:
                                  // Attempt parsing in different formats
                                  for _, format := range []string{time.RFC3339, time.RFC3339Nano, time.RFC822, time.RFC1123} {
                          Severity: Major
                          Found in dataconv/helper.go - About 45 mins to fix

                            Method Machine.runInternal has 6 return statements (exceeds 4 allowed).
                            Open

                            func (m *Machine) runInternal(ctx context.Context, extras StringAnyMap, allowCache bool) (out StringAnyMap, err error) {
                                defer func() {
                                    if r := recover(); r != nil {
                                        err = errorStarlarkPanic("exec", r)
                                    }
                            Severity: Major
                            Found in run.go - About 40 mins to fix

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

                              func readAll(thread *starlark.Thread, b *starlark.Builtin, args starlark.Tuple, kwargs []starlark.Tuple) (starlark.Value, error) {
                                  var (
                                      source                       tps.StringOrBytes
                                      lazyQuotes, trimLeadingSpace bool
                                      skipRow, limitRow            int
                              Severity: Major
                              Found in lib/csv/csv.go - About 40 mins to fix

                                Function goPingWrap has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                Open

                                func goPingWrap(ctx context.Context, address string, count int, timeout, interval time.Duration, pingFunc func(ctx context.Context, address string, timeout time.Duration) (time.Duration, error)) ([]time.Duration, error) {
                                Severity: Minor
                                Found in lib/net/ping.go - About 35 mins to fix

                                  Function setBody has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                  Open

                                  func setBody(req *http.Request, body *types.NullableStringOrBytes, formData *starlark.Dict, formEncoding starlark.String, jsonData starlark.Value) error {
                                  Severity: Minor
                                  Found in lib/http/http.go - About 35 mins to fix

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

                                    func extractIOBottomLines(rd io.Reader, n int) ([]string, error) {
                                        if n <= 0 {
                                            return nil, errors.New("n should be greater than 0")
                                        }
                                        var (
                                    Severity: Major
                                    Found in lib/file/line.go - About 35 mins to fix

                                      Method SharedDict.LoadJSON has 5 return statements (exceeds 4 allowed).
                                      Open

                                      func (s *SharedDict) LoadJSON(jsonStr string) error {
                                          // check the dict itself
                                          if s == nil {
                                              return fmt.Errorf("nil shared dict")
                                          }
                                      Severity: Major
                                      Found in dataconv/share.go - About 35 mins to fix
                                        Severity
                                        Category
                                        Status
                                        Source
                                        Language