Mirroar/hivemind

View on GitHub
src/utils/nav-mesh.ts

Summary

Maintainability
F
1 wk
Test Coverage

Function findPath has a Cognitive Complexity of 80 (exceeds 5 allowed). Consider refactoring.
Open

    findPath(startPos: RoomPosition, endPos: RoomPosition, options?: {maxPathLength?: number; allowDanger?: boolean; maxCpu?: number}): {
        path?: RoomPosition[];
        length?: number;
        incomplete: boolean;
    } {
Severity: Minor
Found in src/utils/nav-mesh.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 nav-mesh.ts has 618 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* global PathFinder Room RoomPosition LEFT RIGHT TOP BOTTOM
TERRAIN_MASK_WALL STRUCTURE_KEEPER_LAIR */

import cache from 'utils/cache';
import hivemind from 'hivemind';
Severity: Major
Found in src/utils/nav-mesh.ts - About 1 day to fix

    Function addConnectingPathsForRegion has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

        addConnectingPathsForRegion(region: RegionInfo, paths: Record<number, Record<number, number>>, roomName: string, costMatrix: CostMatrix) {
            const centerXR = region.center % 50;
            const centerYR = Math.floor(region.center / 50);
    
            for (const exitId of region.exits) {
    Severity: Minor
    Found in src/utils/nav-mesh.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 findPath has 111 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        findPath(startPos: RoomPosition, endPos: RoomPosition, options?: {maxPathLength?: number; allowDanger?: boolean; maxCpu?: number}): {
            path?: RoomPosition[];
            length?: number;
            incomplete: boolean;
        } {
    Severity: Major
    Found in src/utils/nav-mesh.ts - About 4 hrs to fix

      Function getRegions has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          getRegions(exits: ExitInfo[]): RegionInfo[] {
              this.exitLookup = {};
              for (const exit of exits) {
                  this.exitLookup[exit.id] = exit;
              }
      Severity: Minor
      Found in src/utils/nav-mesh.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 getRegions has 77 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          getRegions(exits: ExitInfo[]): RegionInfo[] {
              this.exitLookup = {};
              for (const exit of exits) {
                  this.exitLookup[exit.id] = exit;
              }
      Severity: Major
      Found in src/utils/nav-mesh.ts - About 3 hrs to fix

        NavMesh has 22 functions (exceeds 20 allowed). Consider refactoring.
        Open

        export default class NavMesh {
            memory: NavMemory;
            terrain: RoomTerrain;
            costMatrix: CostMatrix;
            exitLookup: Record<number, ExitInfo>;
        Severity: Minor
        Found in src/utils/nav-mesh.ts - About 2 hrs to fix

          Function getAdjacentRoom has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
          Open

              getAdjacentRoom(roomName: string, exitId: number): string {
                  // @todo Use RoomIntel.getExits() or Game.map.describeExits() instead.
                  const parts = /(\w)(\d+)(\w)(\d+)/.exec(roomName);
          
                  const dir = Math.floor(exitId / 20);
          Severity: Minor
          Found in src/utils/nav-mesh.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 collectExitGroups has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              collectExitGroups(roomName: string, dir: DirectionConstant, vertical: boolean, offset: number): ExitInfo[] {
                  const exits: ExitInfo[] = [];
                  const isAvailable = this.isAvailableExitDirection(roomName, dir);
                  let groupId = 1;
                  let currentStart: number = null;
          Severity: Minor
          Found in src/utils/nav-mesh.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 generateForRoom has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              generateForRoom(roomName: string) {
                  // Mesh doesn't need to be updated very often.
                  // @todo Allow forcing update for when we dismantle a structure.
                  if (
                      this.memory.rooms[roomName]?.paths
          Severity: Minor
          Found in src/utils/nav-mesh.ts - About 1 hr to fix

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

                addConnectingPathsForRegion(region: RegionInfo, paths: Record<number, Record<number, number>>, roomName: string, costMatrix: CostMatrix) {
                    const centerXR = region.center % 50;
                    const centerYR = Math.floor(region.center / 50);
            
                    for (const exitId of region.exits) {
            Severity: Minor
            Found in src/utils/nav-mesh.ts - About 1 hr to fix

              Function getAdjacentRoom has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  getAdjacentRoom(roomName: string, exitId: number): string {
                      // @todo Use RoomIntel.getExits() or Game.map.describeExits() instead.
                      const parts = /(\w)(\d+)(\w)(\d+)/.exec(roomName);
              
                      const dir = Math.floor(exitId / 20);
              Severity: Minor
              Found in src/utils/nav-mesh.ts - About 1 hr to fix

                Function getPortals has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    getPortals(roomName: string) {
                        const portals: Record<string, {
                            targetRoom: string;
                            positions: RoomPosition[];
                            totalX: number;
                Severity: Minor
                Found in src/utils/nav-mesh.ts - About 1 hr to fix

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

                      calculateCostMultiplier(roomName: string, allowDanger: boolean): number {
                          let costMultiplier = 1;
                          if (hivemind.segmentMemory.isReady()) {
                              const roomIntel = getRoomIntel(roomName);
                              if (roomIntel.isOwned()) {
                  Severity: Minor
                  Found in src/utils/nav-mesh.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 collectExitGroups has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      collectExitGroups(roomName: string, dir: DirectionConstant, vertical: boolean, offset: number): ExitInfo[] {
                          const exits: ExitInfo[] = [];
                          const isAvailable = this.isAvailableExitDirection(roomName, dir);
                          let groupId = 1;
                          let currentStart: number = null;
                  Severity: Minor
                  Found in src/utils/nav-mesh.ts - About 1 hr to fix

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

                        generateForRoom(roomName: string) {
                            // Mesh doesn't need to be updated very often.
                            // @todo Allow forcing update for when we dismantle a structure.
                            if (
                                this.memory.rooms[roomName]?.paths
                    Severity: Minor
                    Found in src/utils/nav-mesh.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 getPortals has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                        getPortals(roomName: string) {
                            const portals: Record<string, {
                                targetRoom: string;
                                positions: RoomPosition[];
                                totalX: number;
                    Severity: Minor
                    Found in src/utils/nav-mesh.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

                    Avoid too many return statements within this function.
                    Open

                                        return parts[1] + parts[2] + parts[3] + (Number.parseInt(parts[4], 10) + 1);
                    Severity: Major
                    Found in src/utils/nav-mesh.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                          return parts[1] + parts[2] + 'S0';
                      Severity: Major
                      Found in src/utils/nav-mesh.ts - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                            return 'E0' + parts[3] + parts[4];
                        Severity: Major
                        Found in src/utils/nav-mesh.ts - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                              return parts[1] + (Number.parseInt(parts[2], 10) + 1) + parts[3] + parts[4];
                          Severity: Major
                          Found in src/utils/nav-mesh.ts - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                            return parts[1] + (Number.parseInt(parts[2], 10) - 1) + parts[3] + parts[4];
                            Severity: Major
                            Found in src/utils/nav-mesh.ts - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                              return parts[1] + parts[2] + parts[3] + (Number.parseInt(parts[4], 10) - 1);
                              Severity: Major
                              Found in src/utils/nav-mesh.ts - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                                    return 'W0' + parts[3] + parts[4];
                                Severity: Major
                                Found in src/utils/nav-mesh.ts - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                                  return parts[1] + (Number.parseInt(parts[2], 10) - 1) + parts[3] + parts[4];
                                  Severity: Major
                                  Found in src/utils/nav-mesh.ts - About 30 mins to fix

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

                                                case 0:
                                                    // Exit is due north.
                                                    if (parts[3] === 'N') {
                                                        return parts[1] + parts[2] + parts[3] + (Number.parseInt(parts[4], 10) + 1);
                                                    }
                                    Severity: Major
                                    Found in src/utils/nav-mesh.ts and 1 other location - About 5 hrs to fix
                                    src/utils/nav-mesh.ts on lines 747..757

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

                                    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 2:
                                                    // Exit is due south.
                                                    if (parts[3] === 'S') {
                                                        return parts[1] + parts[2] + parts[3] + (Number.parseInt(parts[4], 10) + 1);
                                                    }
                                    Severity: Major
                                    Found in src/utils/nav-mesh.ts and 1 other location - About 5 hrs to fix
                                    src/utils/nav-mesh.ts on lines 723..733

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

                                    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 1:
                                                    // Exit is due east.
                                                    if (parts[1] === 'E') {
                                                        return parts[1] + (Number.parseInt(parts[2], 10) + 1) + parts[3] + parts[4];
                                                    }
                                    Severity: Major
                                    Found in src/utils/nav-mesh.ts and 1 other location - About 5 hrs to fix
                                    src/utils/nav-mesh.ts on lines 759..769

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

                                    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

                                                default:
                                                    // Exit is due west.
                                                    if (parts[1] === 'W') {
                                                        return parts[1] + (Number.parseInt(parts[2], 10) + 1) + parts[3] + parts[4];
                                                    }
                                    Severity: Major
                                    Found in src/utils/nav-mesh.ts and 1 other location - About 5 hrs to fix
                                    src/utils/nav-mesh.ts on lines 735..745

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

                                    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