raveljs/ravel

View on GitHub
lib/util/route-tree.js

Summary

Maintainability
C
1 day
Test Coverage
A
100%

Function match has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

  match (path, keyValues = {}) {
    if (path.length === 0) {
      if (this.middleware.length > 0) {
        return new RouteTreeResult(keyValues, this.middleware, this.composedMiddleware);
      } else {
Severity: Minor
Found in lib/util/route-tree.js - 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

Function containsFunctionalDuplicate has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

  containsFunctionalDuplicate (pathComponents, catchAll = false) {
    if (pathComponents.length === 0) {
      // if there's no path components to begin with, then this is only a
      // duplicate if we've stored middleware at the "root" path (/)
      // if we reached here via recursion, the same test works.
Severity: Minor
Found in lib/util/route-tree.js - About 1 hr 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 match has 38 lines of code (exceeds 30 allowed). Consider refactoring.
Open

  match (path, keyValues = {}) {
    if (path.length === 0) {
      if (this.middleware.length > 0) {
        return new RouteTreeResult(keyValues, this.middleware, this.composedMiddleware);
      } else {
Severity: Minor
Found in lib/util/route-tree.js - About 1 hr to fix

    Function compare has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

      static compare (lNode, rNode) {
        // catch-all routes have the lowest priority
        if (!lNode.catchAll && rNode.catchAll) {
          return -1;
        } else if (lNode.catchAll && !rNode.catchAll) {
    Severity: Minor
    Found in lib/util/route-tree.js - About 1 hr 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 too many return statements within this function.
    Open

          return -1;
    Severity: Major
    Found in lib/util/route-tree.js - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

          return null;
      Severity: Major
      Found in lib/util/route-tree.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return new RouteTreeResult(keyValues, child.middleware, child.composedMiddleware);
        Severity: Major
        Found in lib/util/route-tree.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                return 0;
          Severity: Major
          Found in lib/util/route-tree.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                  return 1;
            Severity: Major
            Found in lib/util/route-tree.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                    return 1;
              Severity: Major
              Found in lib/util/route-tree.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return 0;
                Severity: Major
                Found in lib/util/route-tree.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                        return -1;
                  Severity: Major
                  Found in lib/util/route-tree.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                          return new RouteTreeResult(keyValues, this.middleware, this.composedMiddleware);
                    Severity: Major
                    Found in lib/util/route-tree.js - About 30 mins to fix

                      Function allowedMethods has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                        allowedMethods () {
                          const methods = [];
                          if (!this[Methods.HEAD].isEmpty) methods.push('HEAD');
                          if (!this[Methods.GET].isEmpty) methods.push('GET');
                          if (!this[Methods.PATCH].isEmpty) methods.push('PATCH');
                      Severity: Minor
                      Found in lib/util/route-tree.js - About 25 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 addRoute has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                        addRoute (pattern, pathComponents, middleware, catchAll = false) {
                          // check if we're done
                          if (pathComponents.length === 0) {
                            _middleware.set(this, middleware);
                            _composedMiddleware.set(this, compose(middleware));
                      Severity: Minor
                      Found in lib/util/route-tree.js - About 25 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

                      There are no issues that match your filters.

                      Category
                      Status