aurelia/aurelia

View on GitHub
packages/router/src/routing-scope.ts

Summary

Maintainability
F
1 wk
Test Coverage

Function processInstructions has a Cognitive Complexity of 99 (exceeds 5 allowed). Consider refactoring.
Open

  public async processInstructions(instructions: RoutingInstruction[], earlierMatchedInstructions: RoutingInstruction[], navigation: Navigation, coordinator: NavigationCoordinator, configuredRoutePath = ''): Promise<Endpoint[]> {
    const router = this.router;
    const options = router.configuration.options;

    // If there are instructions that aren't part of an already found configured route...
Severity: Minor
Found in packages/router/src/routing-scope.ts - 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

File routing-scope.ts has 674 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* eslint-disable prefer-template */
/* eslint-disable max-lines-per-function */
import { NavigationCoordinator } from './navigation-coordinator';
import { IViewportScopeOptions, ViewportScope } from './endpoints/viewport-scope';
import { CustomElement, ICustomElementController, ICustomElementViewModel } from '@aurelia/runtime-html';
Severity: Major
Found in packages/router/src/routing-scope.ts - About 1 day to fix

    Function findMatchingRouteInRoutes has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
    Open

      private findMatchingRouteInRoutes(path: string, routes: Route[], parameters: Parameters): FoundRoute {
        const found = new FoundRoute();
        if (routes.length === 0) {
          return found;
        }
    Severity: Minor
    Found in packages/router/src/routing-scope.ts - About 6 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 processInstructions has 154 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      public async processInstructions(instructions: RoutingInstruction[], earlierMatchedInstructions: RoutingInstruction[], navigation: Navigation, coordinator: NavigationCoordinator, configuredRoutePath = ''): Promise<Endpoint[]> {
        const router = this.router;
        const options = router.configuration.options;
    
        // If there are instructions that aren't part of an already found configured route...
    Severity: Major
    Found in packages/router/src/routing-scope.ts - About 6 hrs to fix

      RoutingScope has 40 functions (exceeds 20 allowed). Consider refactoring.
      Open

      export class RoutingScope {
        /** @internal */
        private static lastId = 0;
      
        public id = ++RoutingScope.lastId;
      Severity: Minor
      Found in packages/router/src/routing-scope.ts - About 5 hrs to fix

        Function findInstructions has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
        Open

          public findInstructions(instructions: RoutingInstruction[], useDirectRouting: boolean, useConfiguredRoutes: boolean): FoundRoute {
            const router = this.router;
            let route = new FoundRoute();
        
            if (useConfiguredRoutes && !RoutingInstruction.containsSiblings(router, instructions)) {
        Severity: Minor
        Found in packages/router/src/routing-scope.ts - About 3 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 for has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
        Open

          public static for(
            origin: Element | ICustomElementViewModel | Viewport | ViewportScope | RoutingScope | ICustomElementController | IContainer | null,
            instruction?: string
          ): { scope: RoutingScope | null; instruction: string | undefined } {
        
        
        Severity: Minor
        Found in packages/router/src/routing-scope.ts - About 3 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 findMatchingRouteInRoutes has 89 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private findMatchingRouteInRoutes(path: string, routes: Route[], parameters: Parameters): FoundRoute {
            const found = new FoundRoute();
            if (routes.length === 0) {
              return found;
            }
        Severity: Major
        Found in packages/router/src/routing-scope.ts - About 3 hrs to fix

          Function for has 47 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            public static for(
              origin: Element | ICustomElementViewModel | Viewport | ViewportScope | RoutingScope | ICustomElementController | IContainer | null,
              instruction?: string
            ): { scope: RoutingScope | null; instruction: string | undefined } {
          
          
          Severity: Minor
          Found in packages/router/src/routing-scope.ts - About 1 hr to fix

            Function findInstructions has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              public findInstructions(instructions: RoutingInstruction[], useDirectRouting: boolean, useConfiguredRoutes: boolean): FoundRoute {
                const router = this.router;
                let route = new FoundRoute();
            
                if (useConfiguredRoutes && !RoutingInstruction.containsSiblings(router, instructions)) {
            Severity: Minor
            Found in packages/router/src/routing-scope.ts - About 1 hr to fix

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

                public findMatchingRoute(path: string, parameters: Parameters): FoundRoute {
                  let found: FoundRoute = new FoundRoute();
                  if (this.isViewportScope && !this.passThroughScope) {
                    found = this.findMatchingRouteInRoutes(path, this.endpoint.getRoutes(), parameters);
                  } else if (this.isViewport) {
              Severity: Minor
              Found in packages/router/src/routing-scope.ts - 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 addEndpoint has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                public addEndpoint(type: EndpointTypeName, name: string, connectedCE: IConnectedCustomElement | null, options: IViewportOptions | IViewportScopeOptions = {}): Viewport | ViewportScope {
                  let endpoint: Endpoint | null = this.getOwnedScopes()
                    .find(scope => scope.type === type &&
                      scope.endpoint.name === name)?.endpoint ?? null;
              
              
              Severity: Minor
              Found in packages/router/src/routing-scope.ts - About 55 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 createUnknownRouteError has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                private createUnknownRouteError(instructions: RoutingInstruction[]) {
                  const options = this.router.configuration.options;
                  const route = RoutingInstruction.stringify(this.router, instructions);
                  // TODO: Add missing/unknown route handling
                  //       shouldn't this check all routes, instead of only the first one?
              Severity: Minor
              Found in packages/router/src/routing-scope.ts - 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

                          for (const nextScopeInstruction of matchedInstruction.nextScopeInstructions!) {
                            nextScopeInstruction.scope = endpoint.scope;
                            nextScopeInstruction.endpoint.instance = null;
                          }
              Severity: Major
              Found in packages/router/src/routing-scope.ts - About 45 mins to fix

                Consider simplifying this complex logical expression.
                Open

                    if (connectedCE != null && endpoint?.connectedCE != null && endpoint.connectedCE !== connectedCE) {
                      endpoint = this.getOwnedScopes(true)
                        .find(scope => scope.type === type &&
                          scope.endpoint.name === name &&
                          scope.endpoint.connectedCE === connectedCE)?.endpoint
                Severity: Major
                Found in packages/router/src/routing-scope.ts - About 40 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return { scope, instruction };
                  Severity: Major
                  Found in packages/router/src/routing-scope.ts - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                          return { scope: null, instruction: instruction.slice(1) };
                    Severity: Major
                    Found in packages/router/src/routing-scope.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                            return new Error("No matching route/component found for '" + route + "'.");
                      Severity: Major
                      Found in packages/router/src/routing-scope.ts - About 30 mins to fix

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

                          public matchScope(instructions: RoutingInstruction[], deep = false): RoutingInstruction[] {
                            const matching: RoutingInstruction[] = [];
                        
                            for (const instruction of instructions) {
                              if (instruction.scope === this) {
                        Severity: Minor
                        Found in packages/router/src/routing-scope.ts - 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 hoistedChildren has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                          public get hoistedChildren(): RoutingScope[] {
                            const scopes = this.enabledChildren;
                            while (scopes.some(scope => scope.passThroughScope)) {
                              for (const scope of scopes.slice()) {
                                if (scope.passThroughScope) {
                        Severity: Minor
                        Found in packages/router/src/routing-scope.ts - 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

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

                          public toStringOwning(recurse = false): string {
                            return `${this.owningScope !== this ? this.owningScope!.toString() : ''}/${!this.enabled ? '(' : ''}${this.endpoint.toString()}#${this.id}${!this.enabled ? ')' : ''}` +
                              `${recurse ? `\n` + this.ownedScopes.map(child => child.toStringOwning(true)).join('') : ''}`;
                          }
                        Severity: Major
                        Found in packages/router/src/routing-scope.ts and 1 other location - About 6 hrs to fix
                        packages/router/src/routing-scope.ts on lines 229..232

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

                        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

                          public toString(recurse = false): string {
                            return `${this.owningScope !== this ? this.owningScope!.toString() : ''}/${!this.enabled ? '(' : ''}${this.endpoint.toString()}#${this.id}${!this.enabled ? ')' : ''}` +
                              `${recurse ? `\n` + this.children.map(child => child.toString(true)).join('') : ''}`;
                          }
                        Severity: Major
                        Found in packages/router/src/routing-scope.ts and 1 other location - About 6 hrs to fix
                        packages/router/src/routing-scope.ts on lines 234..237

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

                        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

                        There are no issues that match your filters.

                        Category
                        Status