Microsoft/fast-dna

View on GitHub
packages/web-components/fast-router/src/recognizer.ts

Summary

Maintainability
F
1 wk
Test Coverage

File recognizer.ts has 676 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Route } from "./navigation.js";
import { QueryString } from "./query-string.js";

/**
 * @beta
Severity: Major
Found in packages/web-components/fast-router/src/recognizer.ts - About 1 day to fix

    Function advance has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

        public advance(ch: string): void {
            const { chars, states, skippedStates, result } = this;
            let stateToAdd: AnyState<T> | null = null;
    
            let matchCount = 0;
    Severity: Minor
    Found in packages/web-components/fast-router/src/recognizer.ts - About 5 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 finalize has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

        public finalize(): void {
            function collectSkippedStates(
                skippedStates: DynamicState<T>[],
                state: AnyState<T>
            ): void {
    Severity: Minor
    Found in packages/web-components/fast-router/src/recognizer.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

    Function compareTo has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        public compareTo(b: Candidate<T>): -1 | 1 | 0 {
            const statesA = this.states;
            const statesB = b.states;
    
            for (
    Severity: Minor
    Found in packages/web-components/fast-router/src/recognizer.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

    Function $add has 65 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private $add(route: Route, settings?: TSettings): void {
            const path = route.path;
            const $route = new ConfigurableRoute(
                route.path,
                route.name || "",
    Severity: Major
    Found in packages/web-components/fast-router/src/recognizer.ts - About 2 hrs to fix

      Function advance has 61 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public advance(ch: string): void {
              const { chars, states, skippedStates, result } = this;
              let stateToAdd: AnyState<T> | null = null;
      
              let matchCount = 0;
      Severity: Major
      Found in packages/web-components/fast-router/src/recognizer.ts - About 2 hrs to fix

        Function compareTo has 61 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public compareTo(b: Candidate<T>): -1 | 1 | 0 {
                const statesA = this.states;
                const statesB = b.states;
        
                for (
        Severity: Major
        Found in packages/web-components/fast-router/src/recognizer.ts - About 2 hrs to fix

          Function recognize has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public async recognize(
                  path: string,
                  converters: Readonly<Record<string, RouteParameterConverter>> = {}
              ): Promise<RecognizedRoute<TSettings> | null> {
                  const separated = QueryString.separate(path);
          Severity: Minor
          Found in packages/web-components/fast-router/src/recognizer.ts - About 1 hr to fix

            Function $add has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                private $add(route: Route, settings?: TSettings): void {
                    const path = route.path;
                    const $route = new ConfigurableRoute(
                        route.path,
                        route.name || "",
            Severity: Minor
            Found in packages/web-components/fast-router/src/recognizer.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 generate has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                private generate(
                    segments: AnySegment<any>[] | undefined,
                    params: object
                ): string | null {
                    if (!segments) {
            Severity: Minor
            Found in packages/web-components/fast-router/src/recognizer.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 $process has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    function $process(
                        nextState: AnyState<T>,
                        skippedState: DynamicState<T> | null
                    ): void {
                        if (nextState.isMatch(ch)) {
            Severity: Minor
            Found in packages/web-components/fast-router/src/recognizer.ts - About 1 hr to fix

              Function generate has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private generate(
                      segments: AnySegment<any>[] | undefined,
                      params: object
                  ): string | null {
                      if (!segments) {
              Severity: Minor
              Found in packages/web-components/fast-router/src/recognizer.ts - About 1 hr to fix

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

                    public constructor(
                        public readonly prevState: AnyState<T> | null,
                        public readonly segment: AnySegment<T> | null,
                        public readonly value: string
                    ) {
                Severity: Minor
                Found in packages/web-components/fast-router/src/recognizer.ts - About 1 hr to fix

                  Function recognize has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public async recognize(
                          path: string,
                          converters: Readonly<Record<string, RouteParameterConverter>> = {}
                      ): Promise<RecognizedRoute<TSettings> | null> {
                          const separated = QueryString.separate(path);
                  Severity: Minor
                  Found in packages/web-components/fast-router/src/recognizer.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 getParams has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public getParams(): Record<string, string | undefined> {
                          const { states, chars, endpoint } = this;
                  
                          const params: Record<string, string | undefined> = {};
                          // First initialize all properties with undefined so they all exist (even if they're not filled, e.g. non-matched optional params)
                  Severity: Minor
                  Found in packages/web-components/fast-router/src/recognizer.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

                                              if (nextState.nextStates !== null) {
                                                  for (const $nextState of nextState.nextStates) {
                                                      collectSkippedStates(skippedStates, $nextState);
                                                  }
                                              }
                  Severity: Major
                  Found in packages/web-components/fast-router/src/recognizer.ts - About 45 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                    return -1;
                    Severity: Major
                    Found in packages/web-components/fast-router/src/recognizer.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return 1;
                      Severity: Major
                      Found in packages/web-components/fast-router/src/recognizer.ts - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                return 0;
                        Severity: Major
                        Found in packages/web-components/fast-router/src/recognizer.ts - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                          return 1;
                          Severity: Major
                          Found in packages/web-components/fast-router/src/recognizer.ts - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                        return 1;
                            Severity: Major
                            Found in packages/web-components/fast-router/src/recognizer.ts - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                              return -1;
                              Severity: Major
                              Found in packages/web-components/fast-router/src/recognizer.ts - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                            return -1;
                                Severity: Major
                                Found in packages/web-components/fast-router/src/recognizer.ts - About 30 mins to fix

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

                                      public appendTo(state: AnyState<T>): StaticState<T> {
                                          const {
                                              value,
                                              value: { length },
                                          } = this;
                                  Severity: Minor
                                  Found in packages/web-components/fast-router/src/recognizer.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

                                  TODO found
                                  Open

                                          // TODO: probably want to warn or even throw here, but leave it be for now.

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

                                      public equals(b: AnySegment<T>): boolean {
                                          return (
                                              b.kind === SegmentKind.dynamic &&
                                              b.optional === this.optional &&
                                              b.name === this.name
                                  Severity: Major
                                  Found in packages/web-components/fast-router/src/recognizer.ts and 1 other location - About 1 hr to fix
                                  packages/web-components/fast-router/src/recognizer.ts on lines 824..830

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

                                  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 equals(b: AnySegment<T>): boolean {
                                          return (
                                              b.kind === SegmentKind.static &&
                                              b.caseSensitive === this.caseSensitive &&
                                              b.value === this.value
                                  Severity: Major
                                  Found in packages/web-components/fast-router/src/recognizer.ts and 1 other location - About 1 hr to fix
                                  packages/web-components/fast-router/src/recognizer.ts on lines 854..860

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

                                  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

                                              case SegmentKind.star:
                                                  this.length = prevState!.length + 1;
                                                  this.isSeparator = false;
                                                  this.isDynamic = true;
                                                  this.isOptional = false;
                                  Severity: Major
                                  Found in packages/web-components/fast-router/src/recognizer.ts and 1 other location - About 1 hr to fix
                                  packages/web-components/fast-router/src/recognizer.ts on lines 706..711

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

                                  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

                                              case SegmentKind.static:
                                                  this.length = prevState!.length + 1;
                                                  this.isSeparator = false;
                                                  this.isDynamic = false;
                                                  this.isOptional = false;
                                  Severity: Major
                                  Found in packages/web-components/fast-router/src/recognizer.ts and 1 other location - About 1 hr to fix
                                  packages/web-components/fast-router/src/recognizer.ts on lines 700..705

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

                                  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

                                      public generate(
                                          params: Record<string, string>,
                                          consumed: Record<string, boolean>
                                      ): string {
                                          consumed[this.name] = true;
                                  Severity: Major
                                  Found in packages/web-components/fast-router/src/recognizer.ts and 1 other location - About 1 hr to fix
                                  packages/web-components/fast-router/src/recognizer.ts on lines 846..852

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

                                  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

                                      public generate(
                                          params: Record<string, string>,
                                          consumed: Record<string, boolean>
                                      ): string {
                                          consumed[this.name] = true;
                                  Severity: Major
                                  Found in packages/web-components/fast-router/src/recognizer.ts and 1 other location - About 1 hr to fix
                                  packages/web-components/fast-router/src/recognizer.ts on lines 875..881

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

                                  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 appendTo(state: AnyState<T>): DynamicState<T> {
                                          state = state.append(/* segment */ this, /* value   */ "/");
                                  
                                          return state;
                                      }
                                  Severity: Major
                                  Found in packages/web-components/fast-router/src/recognizer.ts and 1 other location - About 1 hr to fix
                                  packages/web-components/fast-router/src/recognizer.ts on lines 870..873

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

                                  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 appendTo(state: AnyState<T>): StarState<T> {
                                          state = state.append(/* segment */ this, /* value   */ "");
                                          return state;
                                      }
                                  Severity: Major
                                  Found in packages/web-components/fast-router/src/recognizer.ts and 1 other location - About 1 hr to fix
                                  packages/web-components/fast-router/src/recognizer.ts on lines 840..844

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

                                  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