1set/starlet

View on GitHub
lib/http/http.go

Summary

Maintainability
D
2 days
Test Coverage

Function setBody has a Cognitive Complexity of 67 (exceeds 20 allowed). Consider refactoring.
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: Minor
Found in lib/http/http.go - About 1 day 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

Function setBody has 97 lines of code (exceeds 50 allowed). Consider refactoring.
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 2 hrs to fix

    Method Module.reqMethod has 57 lines of code (exceeds 50 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 1 hr to fix

      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 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

          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

          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 setAuth has 5 return statements (exceeds 4 allowed).
            Open

            func setAuth(req *http.Request, auth starlark.Tuple) error {
                if len(auth) == 0 {
                    return nil
                } else if len(auth) == 2 {
                    username, err := AsString(auth[0])
            Severity: Major
            Found in lib/http/http.go - About 35 mins to fix

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

              func setHeaders(req *http.Request, headers *starlark.Dict) error {
                  var (
                      keys    = headers.Keys()
                      UAKey   = "User-Agent"
                      isUASet = false
              Severity: Major
              Found in lib/http/http.go - About 35 mins to fix

                There are no issues that match your filters.

                Category
                Status