aurelia/aurelia

View on GitHub
packages/router/src/router.ts

Summary

Maintainability
F
4 days
Test Coverage
C
71%

File router.ts has 519 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* eslint-disable prefer-template */
/**
 *
 * NOTE: This file is still WIP and will go through at least one more iteration of refactoring, commenting and clean up!
 * In its current state, it is NOT a good source for learning about the inner workings and design of the router.
Severity: Major
Found in packages/router/src/router.ts - About 1 day to fix

    Function updateNavigation has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

      private async updateNavigation(navigation: Navigation): Promise<void> {
        // Make sure instructions added not from root scope are properly parented
        // up to root scope
        (this.rootScope as ViewportScope).scope.reparentRoutingInstructions();
    
    
    Severity: Minor
    Found in packages/router/src/router.ts - About 4 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

    Router has 29 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class Router implements IRouter {
    
      public static readonly closestEndpointKey = Protocol.annotation.keyFor('closest-endpoint');
    
      /**
    Severity: Minor
    Found in packages/router/src/router.ts - About 3 hrs to fix

      Function applyLoadOptions has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

        public applyLoadOptions(loadInstructions: LoadInstruction | LoadInstruction[], options: ILoadOptions, keepString = true): { instructions: string | RoutingInstruction[]; scope: RoutingScope | null } {
          options = options ?? {};
          if ('origin' in options && !('context' in options)) {
            options.context = options.origin;
          }
      Severity: Minor
      Found in packages/router/src/router.ts - 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 updateNavigation has 57 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private async updateNavigation(navigation: Navigation): Promise<void> {
          // Make sure instructions added not from root scope are properly parented
          // up to root scope
          (this.rootScope as ViewportScope).scope.reparentRoutingInstructions();
      
      
      Severity: Major
      Found in packages/router/src/router.ts - About 2 hrs to fix

        Function appendInstructions has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          public appendInstructions(instructions: RoutingInstruction[], scope: RoutingScope | null = null): void {
            if (scope === null) {
              scope = this.rootScope!.scope;
            }
            for (const instruction of instructions) {
        Severity: Minor
        Found in packages/router/src/router.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 applyLoadOptions has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          public applyLoadOptions(loadInstructions: LoadInstruction | LoadInstruction[], options: ILoadOptions, keepString = true): { instructions: string | RoutingInstruction[]; scope: RoutingScope | null } {
            options = options ?? {};
            if ('origin' in options && !('context' in options)) {
              options.context = options.origin;
            }
        Severity: Minor
        Found in packages/router/src/router.ts - About 1 hr to fix

          Function load has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            public async load(instructions: LoadInstruction | LoadInstruction[], options?: ILoadOptions): Promise<boolean | void> {
              options = options ?? {};
              instructions = this.extractFragment(instructions, options);
              instructions = this.extractQuery(instructions, options);
          
          
          Severity: Minor
          Found in packages/router/src/router.ts - About 1 hr to fix

            Function extractQuery has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              private extractQuery(instructions: LoadInstruction | LoadInstruction[], options: ILoadOptions): LoadInstruction | LoadInstruction[] {
                // If instructions is a string and contains a query string, extract it
                if (typeof instructions === 'string' && options.query == null) {
                  const [path, search] = instructions.split('?');
                  instructions = path;
            Severity: Minor
            Found in packages/router/src/router.ts - About 1 hr to fix

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

                private async _doHandleNavigatorNavigateEvent(event: NavigatorNavigateEvent): Promise<void> {
                  if (this._isProcessingNav) {
                    // We prevent multiple navigation at the same time, but we store the last navigation requested.
                    if (this._pendingNavigation) {
                      // This pending navigation is cancelled
              Severity: Minor
              Found in packages/router/src/router.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 load has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                public async load(instructions: LoadInstruction | LoadInstruction[], options?: ILoadOptions): Promise<boolean | void> {
                  options = options ?? {};
                  instructions = this.extractFragment(instructions, options);
                  instructions = this.extractQuery(instructions, options);
              
              
              Severity: Minor
              Found in packages/router/src/router.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 5 locations. Consider refactoring.
              Open

              export class RouterNavigationEndEvent extends RouterNavigationEvent {
                public static readonly eventName: 'au:router:navigation-end' = 'au:router:navigation-end';
                public static create(navigation: Navigation): RouterNavigationEndEvent {
                  return new RouterNavigationEndEvent(this.eventName, navigation);
                }
              Severity: Major
              Found in packages/router/src/router.ts and 4 other locations - About 1 hr to fix
              packages/router/src/router.ts on lines 982..987
              packages/router/src/router.ts on lines 994..999
              packages/router/src/router.ts on lines 1000..1005
              packages/router/src/router.ts on lines 1006..1011

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

              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 5 locations. Consider refactoring.
              Open

              export class RouterNavigationCancelEvent extends RouterNavigationEvent {
                public static readonly eventName: 'au:router:navigation-cancel' = 'au:router:navigation-cancel';
                public static create(navigation: Navigation): RouterNavigationCancelEvent {
                  return new RouterNavigationCancelEvent(this.eventName, navigation);
                }
              Severity: Major
              Found in packages/router/src/router.ts and 4 other locations - About 1 hr to fix
              packages/router/src/router.ts on lines 982..987
              packages/router/src/router.ts on lines 988..993
              packages/router/src/router.ts on lines 1000..1005
              packages/router/src/router.ts on lines 1006..1011

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

              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 5 locations. Consider refactoring.
              Open

              export class RouterNavigationStartEvent extends RouterNavigationEvent {
                public static readonly eventName: 'au:router:navigation-start' = 'au:router:navigation-start';
                public static create(navigation: Navigation): RouterNavigationStartEvent {
                  return new RouterNavigationStartEvent(this.eventName, navigation);
                }
              Severity: Major
              Found in packages/router/src/router.ts and 4 other locations - About 1 hr to fix
              packages/router/src/router.ts on lines 988..993
              packages/router/src/router.ts on lines 994..999
              packages/router/src/router.ts on lines 1000..1005
              packages/router/src/router.ts on lines 1006..1011

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

              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 5 locations. Consider refactoring.
              Open

              export class RouterNavigationCompleteEvent extends RouterNavigationEvent {
                public static readonly eventName: 'au:router:navigation-complete' = 'au:router:navigation-complete';
                public static create(navigation: Navigation): RouterNavigationCompleteEvent {
                  return new RouterNavigationCompleteEvent(this.eventName, navigation);
                }
              Severity: Major
              Found in packages/router/src/router.ts and 4 other locations - About 1 hr to fix
              packages/router/src/router.ts on lines 982..987
              packages/router/src/router.ts on lines 988..993
              packages/router/src/router.ts on lines 994..999
              packages/router/src/router.ts on lines 1006..1011

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

              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 5 locations. Consider refactoring.
              Open

              export class RouterNavigationErrorEvent extends RouterNavigationEvent {
                public static readonly eventName: 'au:router:navigation-error' = 'au:router:navigation-error';
                public static create(navigation: Navigation): RouterNavigationErrorEvent {
                  return new RouterNavigationErrorEvent(this.eventName, navigation);
                }
              Severity: Major
              Found in packages/router/src/router.ts and 4 other locations - About 1 hr to fix
              packages/router/src/router.ts on lines 982..987
              packages/router/src/router.ts on lines 988..993
              packages/router/src/router.ts on lines 994..999
              packages/router/src/router.ts on lines 1000..1005

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

              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

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

                      for (const loadInstruction of loadInstructions as RoutingInstruction[]) {
                        if (loadInstruction.scope === null) {
                          loadInstruction.scope = scope;
                        }
                      }
              Severity: Minor
              Found in packages/router/src/router.ts and 1 other location - About 35 mins to fix
              packages/router/src/router.ts on lines 638..642

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

              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

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

                    for (const loadInstruction of loadInstructions as RoutingInstruction[]) {
                      if (loadInstruction.scope === null) {
                        loadInstruction.scope = scope;
                      }
                    }
              Severity: Minor
              Found in packages/router/src/router.ts and 1 other location - About 35 mins to fix
              packages/router/src/router.ts on lines 628..632

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

              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

              export class RouterStartEvent extends RouterEvent {
                public static eventName: 'au:router:router-start' = 'au:router:router-start';
                public static create(): RouterStartEvent {
                  return new RouterStartEvent(this.eventName);
                }
              Severity: Minor
              Found in packages/router/src/router.ts and 1 other location - About 35 mins to fix
              packages/router/src/router.ts on lines 969..974

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

              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

              export class RouterStopEvent extends RouterEvent {
                public static eventName: 'au:router:router-stop' = 'au:router:router-stop';
                public static create(): RouterStopEvent {
                  return new RouterStopEvent(this.eventName);
                }
              Severity: Minor
              Found in packages/router/src/router.ts and 1 other location - About 35 mins to fix
              packages/router/src/router.ts on lines 963..968

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

              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